开发者

Resize/Crop image from specific area

开发者 https://www.devze.com 2023-04-08 23:16 出处:网络
I am trying to find a PHP image library script that allow me to select specific area (x, y) from large image and then crop/resize to smaller image.

I am trying to find a PHP image library script that allow me to select specific area (x, y) from large image and then crop/resize to smaller image.

It must not distort开发者_Go百科 the image (resize by stretching and skewing the pics). It may need to 'Zoom In' (or something?) if necessary to overcome this problem.

Which PHP image library script can do this?


WideImage

And here is crop demo.

E.g.

WideImage::load('a.png')->crop(50, 50, 30, 20)->saveToFile('b.jpg');


Either GD (http://php.net/manual/en/book.image.php) or ImageMagick (http://php.net/manual/en/book.imagick.php) can do cropping operations.

On the frontend, Jcrop (http://code.google.com/p/jcrop/) is a nice jQuery plugin if you're looking to do this via a page.


You can use GD to achieve that. Im guessing something like this could do it:

/** 
 *@param string $pathToImage The original image (jpg)
 *@param string $outputImage The name of the output image (jpg)
 *@param int $x The top x coordinate of the portion you want to grab
 *@param int $y The top y coordinate of the portion you want to grab
 *@param int $width the width of the portion you want to grab
 *@param int $height the height of the portion you want to grab
 *@return void
 */
function getImagePortion($pathToImage, $outputImage, $x, $y, $width, $height)
{
    $im = imagecreatefromjpeg($pathToImage);
    $portion = imagecreatetruecolor($width, $height);
    imagecopyresampled($portion, $im, 0, 0, $x, $y, $width, $height, imagesx($im), imagesy($im));
    imagejpeg($portion, $outputImage, 100);
}


I happened to LOVE this class http://www.verot.net/php_class_upload.htm

I know it says upload, but you can also handle local files, and if they are images, it gives you a ton of pretty cool features. you can look them up in http://www.verot.net/php_class_upload_samples.htm

GL

0

精彩评论

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

关注公众号