-
Notifications
You must be signed in to change notification settings - Fork 1
DO NOT MERGE: Image crop & resize #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
giriss
wants to merge
17
commits into
master
Choose a base branch
from
image_crop_resize
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
bb01019
Initial commit
3c97231
Readme updated
8e8844d
Added demo album generation
74aa083
Added upload functionality
f5ddcba
Some updates
e014450
Some updates
880db13
Added crop type to the options available
8f0b8d0
Updated readme
8e28b5c
Updated readme
e9b072d
Updated readme
b77e2b2
Updated readme
5d54017
Updated readme
d8860e4
Updated README
3dc15a0
Updates asked
92e2c66
Update SharinPixResizeDemo.page
giriss bda100e
Update README.md
giriss b135c0b
Update README.md
giriss File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,32 @@ | ||
| # Deploy to Salesforce | ||
|
|
||
| # [Flow](https://github.com/sharinpix/demo-apex/tree/flow) | ||
| [<img src="https://raw.githubusercontent.com/afawcett/githubsfdeploy/master/deploy.png">](https://githubsfdeploy.herokuapp.com?owner=sharinpix&repo=demo-apex&ref=image_crop_resize) | ||
|
|
||
| [<img src="https://raw.githubusercontent.com/afawcett/githubsfdeploy/master/deploy.png">](https://githubsfdeploy.herokuapp.com?owner=sharinpix&repo=demo-apex&ref=flow) | ||
| # Image Crop/Resize | ||
|
|
||
| # Work Order token | ||
| Open your Setup and find the Visualforce page named 'SharinPixResizeDemo'. Preview the Visualforce page. Once on the page, you must click on an image so that the resize options will be available. Set a width, height and crop type then click on the 'Resize' button. | ||
|
|
||
| [<img src="https://raw.githubusercontent.com/afawcett/githubsfdeploy/master/deploy.png">](https://githubsfdeploy.herokuapp.com?owner=sharinpix&repo=demo-apex&ref=work_order_token) | ||
| ## Explaining the crop parameters available | ||
| * scale - The image is made to scale in both horizontally and vertically in order to match the new height and new width. Hence no detail loss but proportion is not maintained. | ||
|
|
||
| <img src="https://raw.githubusercontent.com/Akhilesh05/img/master/scale.jpg"> | ||
|
|
||
| * fit - The image is made to fit either horizontally or vertically in way so as not to lose any detail of the image and also preserve the proportion. Some unused spaces may be left which results in a smaller image than expected. | ||
|
|
||
| <img src="https://raw.githubusercontent.com/Akhilesh05/img/master/fit.jpg"> | ||
|
|
||
| * fill - The image is made to fill completely the new space either horizontally or vertically in way to preserve proportion but some detail might be lost. | ||
|
|
||
| <img src="https://raw.githubusercontent.com/Akhilesh05/img/master/fill.jpg"> | ||
|
|
||
| * pad - Same as for fit but the unused spaces are filled with whitespace. | ||
|
|
||
| <img src="https://raw.githubusercontent.com/Akhilesh05/img/master/pad.jpg"> | ||
|
|
||
| * crop - The image is cropped starting from the center (gravity = center), the image preserves its original zoom level. You can also specify the gravity parameter alongside the crop parameter. | ||
|
|
||
| <img src="https://raw.githubusercontent.com/Akhilesh05/img/master/crop.jpg"> | ||
|
|
||
| * thumb - Used for displaying thumbnails and must always be used alongside the gravity parameter. | ||
|
|
||
| <img src="https://raw.githubusercontent.com/Akhilesh05/img/master/thumb.jpg"> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| public with sharing class SharinPixResizeDemo { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add Ctrl or Controller based on other demos |
||
| public String albumId {get; set;} | ||
| public String parameters {get; set;} | ||
|
|
||
| public SharinPixResizeDemo() { | ||
| albumId = 'SharinPixResizeDemo'; | ||
| parameters = JSON.serialize(new Map<String, Object> { | ||
| 'abilities' => new Map<String, Object> { | ||
| albumId => new Map<String, Object> { | ||
| 'Access' => new Map<String, Object> { | ||
| 'see' => true, | ||
| 'image_list' => true, | ||
| 'image_upload' => true | ||
| } | ||
| } | ||
| }, | ||
| 'Id' => albumId | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * This method resizes/crops an image. | ||
| * | ||
| * @param imageId The image ID of the image that needs to be resized/cropped | ||
| * @param width The new width of the image | ||
| * @param height The new height of the image | ||
| * @param crop The crop type for the resize/crop | ||
| * @return Returns the URL of the resized/cropped image | ||
| */ | ||
| @RemoteAction | ||
| public static String resizeImage(String imageId, Integer width, Integer height, String crop) { | ||
| sharinpix.Utils sharinPixUtils = new sharinpix.Utils(); | ||
| return (String) sharinPixUtils.getImageExternalUrl(new Map<String, Object> { | ||
| 'image_id' => imageId, | ||
| 'sharinpix' => new Map<String, Object> { | ||
| 'download' => false, | ||
| 'auto' => false, | ||
| 'full_size' => false | ||
| }, | ||
| 'transformations' => new Map<String, Object> { | ||
| 'crop' => crop, | ||
| 'width' => width, | ||
| 'height' => height | ||
| } | ||
| }).get('resource_url'); | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <ApexClass xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
| <apiVersion>40.0</apiVersion> | ||
| <status>Active</status> | ||
| </ApexClass> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,12 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <Package xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
| <version>36.0</version> | ||
| <types> | ||
| <members>SharinPixResizeDemo</members> | ||
| <name>ApexPage</name> | ||
| </types> | ||
| <types> | ||
| <members>SharinPixResizeDemo</members> | ||
| <name>ApexClass</name> | ||
| </types> | ||
| <version>40.0</version> | ||
| </Package> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| <apex:page showHeader="true" sidebar="true" controller="SharinPixResizeDemo"> | ||
| <script> | ||
| var latestImageViewed = null; | ||
| var newWindow; | ||
| var ifImageSelected = function (func) { | ||
| if (latestImageViewed) { | ||
| newWindow = window.open('https://s-media-cache-ak0.pinimg.com/originals/0c/44/da/0c44dacf1b038014a6f941131c5e8aa2.gif', '_blank'); | ||
| func(); | ||
| } else { | ||
| alert('Select an image from the album first!'); | ||
| } | ||
| return false; | ||
| } | ||
| var buttonClicked = function() { | ||
| var height = document.getElementById('image_height').value; | ||
| var width = document.getElementById('image_width').value; | ||
| var crop = document.getElementById('crop').value; | ||
| Visualforce.remoting.Manager.invokeAction( | ||
| '{! $RemoteAction.SharinPixResizeDemo.resizeImage }', | ||
| latestImageViewed.public_id, width, height, crop, | ||
| function(res) { | ||
| newWindow.location = res; | ||
| } | ||
| ); | ||
| } | ||
| var eventMethod = window.addEventListener ? "addEventListener" : "attachEvent"; | ||
| var eventer = window[eventMethod]; | ||
| var messageEvent = eventMethod == "attachEvent" ? "onmessage" : "message"; | ||
| eventer(messageEvent, function(e) { | ||
| if (e.origin === 'https://app.sharinpix.com') { | ||
| var data = e.data; | ||
| switch (data.name) { | ||
| case 'viewer-image-viewed': | ||
| latestImageViewed = data.payload.image; | ||
| break; | ||
| case 'viewer-closed': | ||
| latestImageViewed = null | ||
| } | ||
| } | ||
| }, false); | ||
| setInterval(function() { | ||
| var mainForm = document.getElementById('{!$Component.main_form}'); | ||
| var warningMessage = document.getElementById('warning_message'); | ||
| if (!mainForm || !warningMessage) return; | ||
| if (latestImageViewed) { | ||
| mainForm.style.display = 'block'; | ||
| warningMessage.style.display = 'none'; | ||
| } else { | ||
| mainForm.style.display = 'none'; | ||
| warningMessage.style.display = 'block'; | ||
| } | ||
| }, 200) | ||
| </script> | ||
| <apex:canvasApp developerName="Albums" height="450px" width="100%" parameters="{! parameters }" /> | ||
| <apex:form onsubmit="return false" id="main_form"> | ||
| <hr /> | ||
| <h1>Resize/Crop</h1><br /><br /> | ||
| Height:<br /> | ||
| <input type="number" value="100" id="image_height" /><br /><br /> | ||
| Width:<br /> | ||
| <input type="number" value="150" id="image_width" /><br /><br /> | ||
| Crop type:<br /> | ||
| <select id="crop"> | ||
| <option>scale</option> | ||
| <option>fit</option> | ||
| <option>fill</option> | ||
| <option>pad</option> | ||
| <option>crop</option> | ||
| <option>thumb</option> | ||
| </select><br /><br /> | ||
| <apex:commandButton value="Resize" id="resize_button" onclick="return ifImageSelected(buttonClicked)" /> <br /> | ||
| </apex:form> | ||
| <div id="warning_message"> | ||
| Click on an image first... | ||
| </div> | ||
| </apex:page> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <ApexPage xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
| <apiVersion>40.0</apiVersion> | ||
| <availableInTouch>false</availableInTouch> | ||
| <confirmationTokenRequired>false</confirmationTokenRequired> | ||
| <label>SharinPixResizeDemo</label> | ||
| </ApexPage> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fit =>
fitetc