【发布时间】:2018-04-19 08:43:03
【问题描述】:
我正在尝试在 PHP v5.4 上裁剪然后调整图像大小,我已阅读这些资源
- Put PNG over a JPG in PHP
- http://php.net/manual/en/function.imagecopy.php
- http://php.net/manual/en/function.imagecopyresampled.php
- http://php.net/manual/en/function.call-user-func-array.phPP
- PHP watermarking
- http://php.net/manual/en/function.imagecreatetruecolor.php
我的代码基于Cropping image in PHP 的答案(这些图像之间的尺寸差异很大)。
我想将此图像从1151x768 调整为200x82 并裁剪x: 0, y: 686 处的背景部分
我不想用这个问题的整个 600 行来膨胀这个问题,$output 指的是setwidth1200nzpioneerthursday08398 图像
<?php
$output = imagecreatefromjpeg("setwidth1200nzpioneerthursday08398.jpg");
$source_crop_image = imagecreatetruecolor(200, 82);
if(!is_resource($source_crop_image)) {
return $source_crop_image;
}
imagealphablending($output, true);
$source_copy_result = imagecopy($output, $source_crop_image, 0, 0, 0, 686, 200, 82);
$source_copy_result = (bool) $source_copy_result;
if(!$source_copy_result) {
return false;
}
$source_image_result = imagejpeg($source_crop_image, "images/mynewimage.jpg");
$source_image_result = (bool) $source_image_result;
?>
我的头像setwidth1200nzpioneerthursday08398
理想情况下,我试图让它裁剪红色部分,同时保持比例不变,然后调整为200x82
我的结果
我的预期结果(我使用 GIMP 创建了这张图片)。
我不知道为什么我的结果图像是一个黑盒子..
【问题讨论】: