Cropping image in PHP

前端 未结 6 564
不思量自难忘°
不思量自难忘° 2020-11-30 11:01

I\'d like crop an image in PHP and save the file. I know your supposed to use the GD library but i\'m not sure how. Any ideas?

Thanks

6条回答
  •  没有蜡笔的小新
    2020-11-30 11:45

    To crop an image using GD you need to use a combination of GD methods, and if you look at "Example #1" on PHP's documentation of the imagecopyresampled method, it shows you how to crop and output an image, you would just need to add some code to that to capture and write the output to a file...

    http://us2.php.net/manual/en/function.imagecopyresampled.php

    There are also other options, including Image Magick which, if installed on your server, can be accessed directly using PHP's exec method (or similar) or you can install the PHP Imagick extension, which yields higher quality images and, in my opinion, is a little more intuitive and flexible to work with.

    Finally, I've used the open source PHPThumb class library, which has a pretty simple interface and can work with multiple options depending on what's on your server, including ImageMagick and GD.

提交回复
热议问题