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-16-2016 12:30 AM
Hello,
You can use my script actually anywhere...
My best bet would be a business rule working on update / insert that would run the script I provided.
Then you will get the attachments as an array of objects, or will get an empty array if there are no attachments.
Regards,
Michal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-16-2016 01:06 AM
Thanks Michal,
I am using it in Product Catalog., can it be use there ya? updating the catalog item picture also is on the attachment?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-16-2016 01:29 AM
BTW, do I need to change any from your script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-16-2016 02:38 AM
Hello,
I guess you can test the script in the browser console if that suits your needs.
"updating the catalog item picture also is on the attachment?"
- I believe, yes
"BTW, do I need to change any from your script?"
- Yes, depends what you want to get.
1)
Say, you want to display the dimensions in some field, then add field to the catalog form and do
g_form.setValue(<YOUR_ADDED_FIELD>, attachments)
2)
Say, you want to validate the dimension if it's not too big, then after the script do,
for(var i =0; i< attachments.length; i++){
if (attachments[i].height > 500|| attachments[i].width > 500){
alert("The attachment is too big, please remove it");
}
}
To remove the attachment you could query similar to the script I provided, and use gr.delete();
Regards,
Michal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2016 01:20 AM
Thank you Michal and we appreciate your patient to us 😉
1)
Say, you want to display the dimensions in some field, then add field to the catalog form and do
g_form.setValue(<YOUR_ADDED_FIELD>, attachments)
**question: what is 'attachments' ur referring to? is that the value of picture or the image filename? cos I cannot pull the picture name from the filed 'picture' in 'cmdb_hardware_product_model' table
Can you give us sample code for 'g_form.setValue(<YOUR_ADDED_FIELD>, attachments)' ?
