如何使用Guillotine (JS)在服务器上转换图像&干预


How to transform images on server using Guillotine (JS) & Intervention

我使用Guillotine让用户转换图像。没有提供如何在服务器端实际应用转换的说明或示例。使用干预,你如何正确地做到这一点?

使用以下指令将图像发送到服务器:

{ scale: 1.4, angle: 270, x: 10, y: 20, w: 900, h: 675 }

我们如何把这个信息应用到照片上呢?

到目前为止我写的是:

// Gets the true initial orientation
$img->orientate();
// Mirrors the image to what the user sees
$img->flip('v')->flip('h'); 
if(isset($fileData['angle']) && $fileData['angle'] > 0 && $fileData['angle'] < 360){
    $img->rotate($fileData['angle']);
}

您考虑过在PHP中直接使用GD库吗?这就是干预的力量,对于这样一个简单的任务,最好直接找到源头。

您可以使用PHP GD库来调整大小,重塑,裁剪等图像http://php.net/manual/en/ref.image.php

这个脚本节选自一个电子邮件签名创建者,将创建一个横向图像,并将用户的个人资料图片放置在左侧。

// Create image canvas (width, height)
$canvas = imagecreatetruecolor(450, 74);
// Load image
$img = imagecreatefromjpeg($img_path);
// Resize image and add to canvas
imagecopy($canvas, $img, 5, 5, 0, 0, 64, 64);
// Create image
imagejpeg($im);
imagedestroy($im);