Crop from existing file to new X & Y

See all posts Reply

Crop from existing file to new X & Y new!
by kambing, 12 years, 8 months ago
Example from simple imagecopy

$image_width  = '600';
$image_height = '200';
$source_x = (int)$_POST['source_x'];
$source_y = (int)$_POST['source_y'];
$src = imagecreatefromjpeg('current_image.jpg');
$dest = imagecreatetruecolor($image_width, $image_height);
imagecopy($dest, $src, 0, 0, $source_x, $source_y, $image_width, $image_height);

With this class how do I crop current image according to new $source_x & $source_y?Reply
Re: Crop from existing file to new X & Y new!
by colin, 12 years, 8 months ago
Most simply:
$foo->image_resize = true;
$foo->image_x = $image_width;
$foo->image_y = $image_height;

If you want to keep aspect ratio, and remove extra parts of the image that don't fit, you can add:
$foo->image_ratio_crop = true;
Reply
Re: Crop from existing file to new X & Y new!
by kambing, 12 years, 8 months ago
Thanks colin.. yeah that way will crop according to $image_width & $image_height

Here and example http://jsfiddle.net/83qFW/

I want to keep the $image_width & $image_height but just want to crop it by new $source_x & $source_yReply
Re: Crop from existing file to new X & Y new!
by colin, 12 years, 8 months ago
I see.

You can use image_precrop for that. See this thread.Reply
Re: Crop from existing file to new X & Y new!
by kambing, 12 years, 8 months ago
Thank you so much colin! I owe you a Coffee. Greatest image class ;)Reply
Re: Crop from existing file to new X & Y new!
by colin, 12 years, 8 months ago
You're welcome :)

If you really want to buy me a coffee, there is a way here!Reply