diff --git a/README.md b/README.md index b492c6a..476866a 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,17 @@ -# [Flow](https://github.com/sharinpix/demo-apex/tree/flow) +# Making image mashup/collage of all images in album -[](https://githubsfdeploy.herokuapp.com?owner=sharinpix&repo=demo-apex&ref=flow) +Below is an example of a resulting collage. -# Work Order token + -[](https://githubsfdeploy.herokuapp.com?owner=sharinpix&repo=demo-apex&ref=work_order_token) +For this demo, you need to open the Visualforce page named `SharinPixCollageDemo`. +Once on this page, you will have the following values to fill. +* columns - The amount of columns you want your collage to have. +* rows - The amount of rows you want your collage to have. +* width - The width of individual images in the collage. +* height - The height of individual images in the collage. +* crop type - The crop type, [as explained here](https://github.com/SharinPix/demo-apex/tree/image_crop_resize). +* background - The background color. + +[](https://githubsfdeploy.herokuapp.com?owner=sharinpix&repo=demo-apex&ref=image_collage_mashup) \ No newline at end of file diff --git a/src/classes/SharinPixCollageDemo.cls b/src/classes/SharinPixCollageDemo.cls new file mode 100644 index 0000000..d8e4827 --- /dev/null +++ b/src/classes/SharinPixCollageDemo.cls @@ -0,0 +1,90 @@ +public with sharing class SharinPixCollageDemo { + public String parameters {get; private set;} + public String albumId {get; private set;} + + public SharinPixCollageDemo() { + albumId = 'SharinPixCollageDemo'; + parameters = JSON.serialize(new Map { + 'abilities' => new Map { + albumId => new Map { + 'Access' => new Map { + 'see' => true, + 'image_list' => true, + 'image_upload' => true + } + } + }, + 'Id' => albumId + }); + } + + /** + * This method generates a collage from all the images of an album. + * + * @param albumId The album ID of the album that will be used to generate the collage + * @param columns The number of columns that a collage will contain + * @param rows The number of rows that a collage will contain + * @param width The width of each image in the collage + * @param height The height of each image in the collage + * @param cropType The crop type that will be used for this collage + * @param background The background color that will be used for the collage + * @return Returns the list of collage URLs generated + */ + @RemoteAction + public static List generateCollage(String albumId, Integer columns, Integer rows, Integer width, Integer height, String cropType, String background) { + SharinPix.Utils sharinPixUtils = new SharinPix.Utils(); + List images = sharinPixUtils.getAlbumImages(albumId); + List imagePublicIds = new List(); + for (Object imageObj: images) { + Map image = (Map) imageObj; + imagePublicIds.add((String) image.get('public_id')); + } + List> imageParams = new List>(); + for (Integer i = 0; i < imagePublicIds.size(); i++) { + String currentId = imagePublicIds.get(i); + Integer pic = (i / columns) / rows; + Integer row = Math.mod((i / columns), rows); + Integer column = Math.mod(i, columns); + if (row == 0 && column == 0) { + imageParams.add(new Map { + 'id' => currentId, + 'transformation' => new List> { + new Map { + 'width' => width, + 'height' => height, + 'crop' => cropType, + 'background' => background + } + } + }); + } else { + List> transformation = (List>) imageParams.get(pic).get('transformation'); + transformation.add(new Map { + 'overlay' => currentId, + 'width' => width, + 'height' => height, + 'crop' => cropType, + 'x' => column * width, + 'y' => row * height, + 'background' => background, + 'gravity' => 'north_west' + }); + } + } + List imageUrls = new List(); + for (Map imageParam: imageParams) { + Map sharinpix = new Map { + 'download' => false, + 'auto' => false, + 'full_size' => false + }; + imageUrls.add((String) sharinPixUtils.getImageExternalUrl(new Map { + 'image_id' => (String) imageParam.get('id'), + 'sharinpix' => sharinpix, + 'transformations' => (List) imageParam.get('transformation') + }).get('resource_url')); + } + return imageUrls; + } + +} \ No newline at end of file diff --git a/src/classes/SharinPixCollageDemo.cls-meta.xml b/src/classes/SharinPixCollageDemo.cls-meta.xml new file mode 100644 index 0000000..94f6f06 --- /dev/null +++ b/src/classes/SharinPixCollageDemo.cls-meta.xml @@ -0,0 +1,5 @@ + + + 40.0 + Active + diff --git a/src/package.xml b/src/package.xml index a9c5799..4ae68bd 100644 --- a/src/package.xml +++ b/src/package.xml @@ -1,4 +1,12 @@ - 36.0 + + SharinPixCollageDemo + ApexPage + + + SharinPixCollageDemo + ApexClass + + 40.0 diff --git a/src/pages/SharinPixCollageDemo.page b/src/pages/SharinPixCollageDemo.page new file mode 100644 index 0000000..c72fbcf --- /dev/null +++ b/src/pages/SharinPixCollageDemo.page @@ -0,0 +1,117 @@ + + + + +
+ +
+
+
+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+
+ +
+
+
+
+ +
+ +
+
+
+ +
+
+
+
+
+
+ +

Collage generated

+
+
+
\ No newline at end of file diff --git a/src/pages/SharinPixCollageDemo.page-meta.xml b/src/pages/SharinPixCollageDemo.page-meta.xml new file mode 100644 index 0000000..67e10e0 --- /dev/null +++ b/src/pages/SharinPixCollageDemo.page-meta.xml @@ -0,0 +1,7 @@ + + + 40.0 + false + false + +