从提交时的编码数据裁剪图像-(File Pond-FilePondPluginFileEncode-imageEditEditor-Doka-Crop-PHP)

从提交时的编码数据裁剪图像-(File Pond-FilePondPluginFileEncode-imageEditEditor-Doka-Crop-PHP),php,crop,image-editing,filepond,Php,Crop,Image Editing,Filepond,使用“FilePondPluginFileEncode”时从隐藏字段传递的数据裁剪图像时,是否有合适的PHP代码可供使用?(我使用Doka作为图像编辑器) 当我选择一个图像,然后编辑裁剪时,下面的选项作为编码元数据从隐藏字段中的文件池中传递base64图像字符串() 提交时:这是我写给crop的内容。它会进行剂量裁剪,但并不像我们从文件池doka图像编辑器中选择的那样精确裁剪 <?php if (isset($file_format['metadata']['crop'])) {

使用“FilePondPluginFileEncode”时从隐藏字段传递的数据裁剪图像时,是否有合适的PHP代码可供使用?(我使用Doka作为图像编辑器)

当我选择一个图像,然后编辑裁剪时,下面的选项作为编码元数据从隐藏字段中的文件池中传递base64图像字符串()

提交时:这是我写给crop的内容。它会进行剂量裁剪,但并不像我们从文件池doka图像编辑器中选择的那样精确裁剪

<?php
if (isset($file_format['metadata']['crop'])) {
            $im = new \Imagick($uploaded_file->getRealPath());

            $aspectRatio = $file_format['metadata']['crop']['aspectRatio'];
            $crop_center_x = $file_format['metadata']['crop']['center']['x'];//percentage
            $crop_center_y = $file_format['metadata']['crop']['center']['y'];//percentage
            $scale =  $file_format['metadata']['crop']['zoom'];

            //Doka formula for aspectRatio = height/width
            //scale to original size but this crop width and height is slightly larger that what we select
            //this may need some improvement
            $crop_width  = ($im->getImageHeight()/$aspectRatio)/$scale; //width of crop selected
            $crop_height = ($im->getImageWidth()*$aspectRatio )/$scale; //height of crop selected

            //x_of_crop
            $x_center_crop =  $im->getImageWidth() * $crop_center_x; //pixels from left to crop center
            $y_center_crop = $im->getImageHeight() * $crop_center_y; //pixels from top to crop center

            $x_left = $x_center_crop - ($crop_width/2);//left position of crop
            $y_top = $y_center_crop - ($crop_height/2);//top position of crop

            $im->cropImaxge($crop_width,$crop_height,$x_left,$y_top);
            file_put_contents($filePath, $im);
            $uploaded_file = new UploadedFile($filePath, $file_format['name'], null, null, true);
        }
?>

我们这样做是否正确,或者我们是否可以选择使用裁剪后的图像数据更新base64字符串,这样就不必在服务器端进行裁剪


任何帮助都将不胜感激

记住在FilePond实例中使用
ImageEditor:Doka.create({})
时,将FilePondPluginImageTransform和FilePondPluginFileEncode添加到FilePond.registerPlugin

 FilePond.registerPlugin(

        **FilePondPluginImageTransform,**
        FilePondPluginFileEncode,
        FilePondPluginFileValidateSize,
        FilePondPluginFileValidateType,
        FilePondPluginImagePreview,
        FilePondPluginImageEdit

      );
通过添加FilePondPluginImageTransform文件,pond也将更新基于64数据的裁剪图像。否则,它将只更新元数据字段

因此,无需使用PHP进行裁剪。Javascript将裁剪并在数据中提供裁剪后的图像base64字符串

不使用编码字符串的示例:


可用插件:

如果您确实想在服务器上应用裁剪,您可以使用,请注意,这目前不支持所有客户端功能(过滤器、标记、颜色等)。repo可能也会引起兴趣。谢谢@Rik.)
 FilePond.registerPlugin(

        **FilePondPluginImageTransform,**
        FilePondPluginFileEncode,
        FilePondPluginFileValidateSize,
        FilePondPluginFileValidateType,
        FilePondPluginImagePreview,
        FilePondPluginImageEdit

      );
FilePond.create(
   field.
   {
     imageEditEditor: Doka.create({})
   }
)