How to calculate Image width and height?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-29-2016 02:31 AM
Hello,
I have a requirement in which we have to validate image width and height of the image file attached to the catalog request.
There is similar functionality in Images(db_image) table OOB. if we upload any image it directly calculates image width and height but I am unable to trace the code which is performing this functionality.
Please suggest an approach or possible solution to perform this activity.
Note: Our instance is in Fuji
Best Regards,
Rajesh M.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-15-2016 10:30 PM
Hi Raj,
Try this On Load client script below. It works perfectly fine for me :
function onLoad() {
//Type appropriate comment here, and begin script below
var maxheight = 1000;
var maxwidth = 1000;
var valid = true;
window.myisvalidimage = function(){
return valid;
};
$j('#sc_attachment_button').on('click', function( e ) {
setTimeout(function (){
$j('#attachFile').on('change', function( evt ) {
if (typeof (this.files) != "undefined") {
var reader = new FileReader();
//Read the contents of Image File.
reader.readAsDataURL(this.files[0]);
reader.onload = function (e) {
//Initiate the JavaScript Image object.
var image = new Image();
//Set the Base64 string return from FileReader as source.
image.src = e.target.result;
image.onload = function () {
//Determine the Height and Width.
var height = this.height;
var width = this.width;
if (height > maxheight || width > maxwidth) {
valid = false;
alert("Height and Width must not exceed 100px.Please Delete and Re-upload !");
return false;
}
alert("Uploaded image has valid Height and Width.");
return true;
};
};
} else {
alert("This browser does not support HTML5.");
return false;
}
});
},3000);
});
}
Make the necessary variable changes and you are good to go !!!
Thanks,
Arnab

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-20-2016 01:19 AM
Hi Arnab,
Which necessary variable to be change for example are you referring to?
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-15-2016 11:03 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-15-2016 11:09 PM
Hi,
client side solution will no give you consistent result on different browsers. i would suggest server side approach. make one on submit client script and query attachment table for images and fetch image height and width and do your validation.
i hope this helps.
(please mark helpful/correct/like based on impact)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-15-2016 11:17 PM
Hi Rushit,
you mean do a 'UI Actions' ? can guide us more?
Thanks