How to resize an image using PHP? [duplicate]

这一生的挚爱 提交于 2019-12-04 05:21:27

问题


Possible Duplicate:
Resize a picture to a fixed size

How to resize an image in PHP?


回答1:


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




回答2:


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




回答3:


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




回答4:


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




回答5:


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().



回答6:


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!



来源:https://stackoverflow.com/questions/3004971/how-to-resize-an-image-using-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!