开发者

Is it possible to use jquery to resize an image?

Can I use JQuery to resize an image that is not on my local server?

Lets say I have an image on www.example.com/dir/images/myImage.jpg

And I want to resize the image on my server www.loc开发者_如何转开发alhost.com

Will it still work?


You can load that image from example.com, and you can change the scale at which it is presented on your page, but you can't edit the file itself. You can either use the height and width tags that Masoud commented, or you can use CSS to edit that element's width+height properties.


You can use jQuery to resize it like this:

$('img#imageidhere').css({
    'width':'xxx',
    'height':'yyy'
});

However, this will only change the CSS which won't resize the image itself, as Chazbot said, this will only change the size in which it is presented on your page.

I figured this was a more appropriate answer since you asked about jQuery and he gave you an answer in HTML and CSS.

Here is an example of it in action: http://jsfiddle.net/qdWMv/

Guide to which method to use:

CSS:

You should use CSS to resize the image if it's only for the purpose of displaying an image on your page and you don't plan to change it. (or if you do plan to change it, you can set the default size using a CSS style on your page)

jQuery

Use jQuery like I suggested if you are going to dynamically change the display size of the image on the page dynamically for any reason.

PHP

PHP is the only method that will change the actual file itself. So if you actually need to change the size of the file itself for any reason then use PHP.


If you have PHP5 and the HTTP stream wrapper enabled on your server, it's incredibly simple to copy it to a local file:

copy('http://somedomain.com/file.jpeg', '/tmp/file.jpeg');

link from : Copy Image from Remote Server Over HTTP
After copy and download the image you can resize image by using jquery image resizer
i mostly use this jquery resizer

or you can also used jquery thumbnail generator ..

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜