You need to sign in to do that
Don't have an account?

Validating Image Dimensions (width and height) of an image saved as an attachment
Hello, I need to validate the image dimensions, i.e. its width and height, in APEX Code. Is there any way in which i can do this after retrieving the image which is saved as an Attachment record. Please suggest some alternative ways to do this if you know. Any help would be appreciated. Thanks, Avinash Kaltari.
Hi, I'm not 100% sure of this approach by any means, so take it with a grain of salt...
There is an Exif jquery plugin which you can use to parse a file and extract various bits of data including dimensions.
However, it fetches the image file so it can read it. So, n once you've loaded it as an attachment you have to dynamically build an <img> tag using the URL to read the file and then use the plugin to re-read it, something like:
.... once you've loaded that attachment with new id of AttachId you need to get that ID back to the javascript somehow..
In your Controller I'd presume that's where you're saving the attachment. So store the Id of the new attachment in a string so the javascript can access it:
public ID attachmentId {get; set;}
In the javascript,
imgsrc='/servlet/servlet.FileDownload?file={!attachmentId}'
put some sort of DIV in your VF page: <div id="UploadedImageDiv"></div>
and later:
$('div#UploadedImageDiv').append('<img/>', {id:UploadedImage, src: imgSrc});
Then you can use the jquery plugin below on the $('img#UploadedImage') to fetch Dimensions, etc.
http://blog.nihilogic.dk/2008/05/jquery-exif-data-plugin.html
Best, Steve.
p.s. Again, big grain of salt... I was just curious about your question and so I looked into it... I've not tried this.
Actually, now that I re-read your posting, you can use the jquery once your user has browsed and given you the URL. You don't need to create the attachment first at all, just build an IMG tag on the URL the user returns and go from there.
-Steve