crop using coordinates?

See all posts Reply

crop using coordinates? new!
by Cassiano Rabelo, 16 years, 9 months ago
Hello Verot.
Is it possible to crop using coordinates like X1,Y1,X2,Y2. Those numbers would define a rectangle in the image and the area inside it should be kept. I tried many combinations of "image_ratio_crop" and "image_crop" without success.
Thank you for your help and for the extension :)Reply
Re: crop using coordinates? new!
by colin, 16 years, 9 months ago
Try something like this:
if ($handle->uploaded) {
  if ($handle->file_is_image) {
    $handle->image_convert = 'jpg';
    $handle->image_crop = array($y1, $handle->image_src_x - $x2, $handle->image_src_y - $y2, $x1);
    $handle->process('/my/dir/');
  }
}
Reply
Re: crop using coordinates? new!
by Daniel Medina, 15 years, 11 months ago
And what I can do to resize the image from this area (x1,y1,x2,y2) to a proporcional size?

By the way, I'm using JScropper UI 1.2.0Reply
Re: crop using coordinates? new!
by colin, 15 years, 11 months ago
Use the code above, and then also use one of the image_ratio parameter, alongside image_x and/or image_y.Reply
Re: crop using coordinates? new!
by Daniel Medina, 15 years, 11 months ago
I had the same problem again. I selected an area from a picture and the final image has the same area.

I need to create a new image with 197x70 pixels. Sometimes, the area selected is bigger than this, so i need to do a proportional resize.

here is a part of my code
$upload->image_convert = 'jpg';
$upload->jpeg_quality = 85;
$upload->image_crop=array($_POST["y1"], $upload->image_src_x - $_POST["x2"], $upload->image_src_y - $_POST["y2"], $_POST["x1"]);
$upload->image_ratio=true;
$upload->image_x=197;
$upload->image_ratio_y=true;		
$upload->process('/mydir/');
Reply
Re: crop using coordinates? new!
by colin, 15 years, 11 months ago
You can use only one image_ratio..... parameter at the same time.

If you have an area of any size, and want to make it fit within 197x70, you have two alternatives:

1. You make it fit within 197x70, the area is resized proportionally, but the image will not fill all 197x70 (there may be some space on the sides or top and bottom). You would do:
$upload->image_x=197;
$upload->image_y=70;
$upload->image_ratio=true;            
$upload->process('/mydir/');

2. You make it fit within 197x70, the area is resized proportionally, and the image will not fill all 197x70 (some parts of the area will be cut off so that the proportional image fits in 197x70). You would do:
$upload->image_x=197;
$upload->image_y=70;
$upload->image_ratio_crop=true;            
$upload->process('/mydir/');
Reply
Re: crop using coordinates? new!
by Daniel Medina, 15 years, 11 months ago
You don't understood me. Sorry about my bad english.

I use a tool called jsCropper. With this tool, after some settings, I can select a region of a picture of any size. This region's area is always proportional to 197x70 pixels, but can be bigger or samaller than 197x70.

This is a picture of application: http://img156.imageshack.us/my.php?image=cropperij3.png

So, the point is: how can I work ONLY with the selected region and resize this region to the final size that will be ALWAYS 197x70?

Again, sorry about my bad english. I realy need an english course... :)Reply
Re: crop using coordinates? new!
by colin, 15 years, 11 months ago
I see what you mean. You will have to use the new dev version 0.27RC1. This version adds a parameter called image_precrop, which works as image_crop except that it crops the image before any resizing.

Here is how your code should look like with 0.27RC1:

$upload->image_resize = true;
$upload->jpeg_quality = 85;
$upload->image_precrop = array($_POST["y1"], $upload->image_src_x - $_POST["x2"], $upload->image_src_y - $_POST["y2"], $_POST["x1"]);
$upload->image_x = 197;
$upload->image_y = 70;

Note that you don't need any image_ratio... here, as your selected area will always be proportional to 197x70.Reply
Re: crop using coordinates? new!
by Daniel Medina, 15 years, 11 months ago
Worked very well!
Thanks!Reply