dongxiang5879 2016-02-25 22:10
浏览 71
已采纳

如何使用来自jQuery Guillotine Plugin和Imagick的数据裁剪图像

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,

  • 写回答

2条回答 默认 最新

  • duanjiaonie6097 2016-02-26 07:43
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵