Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to calculate Image width and height?

Rajesh M1
Giga Guru

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.

19 REPLIES 19

Our aim is to validate incoming picture/image to have only a dimensions of 150x150 with min 10kb and max 30kb size.



Untitled.png


spartacus1
Tera Contributor

Anybody please? thanks


michal29
Mega Guru

Hello spartacus,



I was away for a time, so here comes my delayed response:


**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


-> attachments is the variable in my script that is a table of objects.



  result.height = ga_att.image_height;


  result.width = ga_att.image_width;


  result.size = ga_att.size_bytes;


  result.file_name = ga_att.file_name;


              attachments.push(result)



So use it like:



var imageDetails = "Width: " + attachments[0].width + "Height: " + attachments[0].height;


g_form.setValue('short_description',   imageDetails);



Regards,


Michal


Hi Michal,



Thanks for the reply, appreciate it. I will try it then let you know after.



rgds.


michal29
Mega Guru

Hello Daniel,



No, you don't need to do that, but remember that:


Note: the result of this query is empty, without the roles sys_attachment.



That is because you need a role sys_attachment that admin DOES NOT overwrite.



Reagrds,


Michal