Monday 18 August 2014

How to resize image diagonally using javascript 0

In general we don't like to see our images stretched in view. In this case, If we want to reduce size diagonally, what should we do?

We can do it by changing width property of image.

  • First We need to get original width of image using javascript's naturalWidth property. 
  • Then Multiply it with 0.5 to get 50% reduced image.
  • If you want 2x larger image, then multiply it with 2. like this below code,
domElement.width = doemElement.naturalWidth * 0.5;
  • Then assign resultant number to image width.

Still you have doubt??? see this below DEMO. It will make you understand what I'm saying.

Related Post : HTML DOM Image naturalWidth, naturalHeight Property

0 comments:

Post a Comment