【问题标题】:PHP Cropping Resizing Creates BorderPHP裁剪调整大小创建边框
【发布时间】:2018-01-11 02:53:33
【问题描述】:

使用Croppic 中的示例,当我裁剪一些图像时,我总是在图像的一侧或多侧出现边框。示例:

这是我用来处理图像的代码:

     // original sizes
    $imgInitW = $request->get('imgInitW');
    $imgInitH = $request->get('imgInitH');
     // resized sizes
    $imgW = $request->get('imgW');
    $imgH = $request->get('imgH');
     // offsets
    $imgY1 = $request->get('imgY1');
    $imgX1 = $request->get('imgX1');
     // crop box
    $cropW = $request->get('cropW');
    $cropH = $request->get('cropH');
     // rotation angle

     $output_filename = sys_get_temp_dir() . "/croppedImg_" . rand();

    $source_image = imagecreatefromjpeg($media->getPath());

    $type = '.jpeg';

    // resize the original image to size of editor
    $resizedImage = imagecreatetruecolor($imgW, $imgH);

    imagecopyresampled($resizedImage, $source_image, 0, 0, 0, 0, $imgW, $imgH, $imgInitW, $imgInitH);

    // rotate the rezized image
    $rotated_image = imagerotate($resizedImage, -$angle, 0);
    // find new width & height of rotated image
    $rotated_width = imagesx($rotated_image);
    $rotated_height = imagesy($rotated_image);
    // diff between rotated & original sizes
    $dx = $rotated_width - $imgW;
    $dy = $rotated_height - $imgH;
    // crop rotated image to fit into original rezized rectangle
    $cropped_rotated_image = imagecreatetruecolor($imgW, $imgH);
    imagecolortransparent($cropped_rotated_image, imagecolorallocate($cropped_rotated_image, 0, 0, 0));

    imagecopyresampled($cropped_rotated_image, $rotated_image, 0, 0, $dx / 2, $dy / 2, $imgW, $imgH, $imgW, $imgH);
    // crop image into selected area
    $final_image = imagecreatetruecolor($cropW, $cropH);
    imagecolortransparent($final_image, imagecolorallocate($final_image, 0, 0, 0));
    imagecopyresampled($final_image, $cropped_rotated_image, 0, 0, $imgX1, $imgY1, $cropW, $cropH, $cropW, $cropH);
    // finally output png image
    //imagepng($final_image, $output_filename.$type, $png_quality);
    imagejpeg($final_image, $output_filename . $type, '100');

这通常只发生在我尽可能缩小croppic window 中的图像时。

我不知所措,并尝试调整我能找到的每个参数。有什么想法吗?

【问题讨论】:

    标签: php image-processing croppic


    【解决方案1】:

    我居然找到了答案here。我应用了分叉版本,它正在工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-10-03
      • 2015-02-01
      • 2010-11-03
      • 2018-09-22
      • 2011-11-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多