I've searched everywhere for two days now, still no help.
my project uses jQuery Guillotine Plugin to allow users select image size and position before uploading to my php server but i can't figure out the proper way to crop and scale the image based on the data received from the frontend.
Here is what i've tried:
The response i'm trying to work with looks like this:
{ scale: 0.324, angle: 0, x: 110, y: 34, w: 300, h: 300 }
Then the php code:
$imagick = Image::make($destination . "/" . $fileName);
$height = $imagick->height();
$width = $imagick->width();
$imagick->rotate($req['angle']);
//using the data recieved after user selection
$imagick->cropImage((int)$req['w'], (int)$req['h'], (int)$req['x'], (int)$req['y']);
//Write image to disk
$imagick->save($destinationPathSmaller . $fileName);
At this point, the picture doesn't display correctly. i really don't know what to do, this is my 3rd day on this. please help!
Thanks in inadvance,
Okay, so i finally got it working.
I thank everyone that tried to help, here is what i did in case someone else is faced with same issue:
Using Intervention and Imagick as the driver.
After collecting your data from the guillotine API, process it and use it like this.
$imagick = Image::make($destination . "/" . $fileName);
$width = $imagick->width() * $req['scale'];
$imagick->rotate($req['angle']);
$imagick->widen($width);
//Crop to desired width and height.
//Note: the width and height has to be same with what you set on your Guillotine config when instantiating it.
$imagick->crop($req['w'], $req['h'], $req['x'], $req['y']);
//Finally, Save your file
$imagick->save($new_destination . $fileName);
That should just work perfectly.
I'm not sure if it's just a different in copying and pasting but I think this may be a simple misusage of the library.
For one. You have this line:
$imagick = new Image($destination . "/" . $fileName);
But they suggest that you use
$imagick = Image::make($destination . "/" . $fileName);
The difference between the two is that a driver is not getting set if you simply call new Image
. So the crop method simply bounces off the AbstractDriver class they have and does nothing. But you can call Image::make
and it will return the driver.
If that doesn't seem to be the case then I also noticed that you're using writeImage
. PHP Interventions method for creating a file based on changes is ->save();
. I couldn't find the method writeImage
anywhere.