开发者

How to resize an image using PHP? [duplicate]

This question already has answers here: Closed 12 years ago.

Possible Duplicate:

Resize a picture to a fixed size

How to res开发者_如何学JAVAize an image in PHP?


Try the GD and Image functions, or - if you want something more than just that - a library like ImageMagick.


You may use imagemagick, call it via exec("convert ...") from php, copy it to the desired location and access it.


You can also do like I do and use a lightweight framework like flourishlib.com where everything is nicely wrapped in a class fImage, example from documentation:

// Saving as a 60 quality JPEG
$image2 = new fImage('./example.gif');
$image2->resize(250, 0);
$image2->saveChanges('jpeg', 60);

It will work with both GD and ImageMagick


I'm using Image_Transform PEAR package for it. A ready-made thing that's pretty solid at this task.


You may use codeigniter framework which provides you a lot of tools, including image manipulation. Otherwize, the main idea is to:

  • open your picture (jpg for instance) with imagecreatefromjpeg()
  • create a new picture using imagecreatetruecolor()
  • use imagecopyresampled()
  • finally to save it with imagejpeg().


Here is the code to a Image resize script which i wrote a while back. It resizes the image and keeps the aspect ratio.

This script uses the core GD library to resize. So hopefully your host already got it installed.

I did some fast translation on the documentation from swedish to english. So it might not be perfect.

Hope it works!

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜