Mediator
Mediator

Reputation: 15378

How to resize an image in JQuery

as here to change the size? I can not find the right method

var img = new Image();
img.src = newImg.ImagePath;

Upvotes: 0

Views: 468

Answers (2)

Alexander
Alexander

Reputation: 23537

A 100px x 100px image.

var img    = new Image();
img.src    = newImg.ImagePath;
img.width  = 100;
img.height = 100;

Upvotes: 1

ThiefMaster
ThiefMaster

Reputation: 318698

$(img).width(width_in_pixels).height(height_in_pixels);

Instead of $(img) you can also use a $('selector'). If you want to create a new one, use this:

$('<img/>', {src: 'url to the image'}).width(width_in_pixels).height(height_in_pixels).appendTo('#someElement');

Upvotes: 2

Related Questions