I have found a bug with copying source image if source image sizes is smaller that destination field size.
In this case function imageapi_gd_image_crop() receive negative $x and $y values. And function imagecopyresampled() copies black color instead of transparent color to destination image.
I modify function imageapi_gd_image_crop() from original
function imageapi_gd_image_crop(&$image, $x, $y, $width, $height) {
$res = _gd_create_tmp($image, $width, $height);
if (!imagecopyresampled($res, $image->res, 0, 0, $x, $y, $width, $height, $width, $height)) {
return false;
}
// destroy the original image and return the modified image.
imagedestroy($image->res);
$image->res = $res;
$image->info['width'] = $width;
$image->info['height'] = $height;
return true;
}
to this:
function imageapi_gd_image_crop(&$image, $x, $y, $width, $height) {
$res = _gd_create_tmp($image, $width, $height);
$src_width=min($image->info['width'],$width);
$src_height=min($image->info['height'],$height);
$src_x=max(0,$x);
$src_y=max(0,$y);
$dst_x=max(0,-$x);
$dst_y=max(0,-$y);
if (!imagecopy($res, $image->res, $dst_x, $dst_y, $src_x, $src_y, $src_width, $src_height)) {
return false;
}
// destroy the original image and return the modified image.
imagedestroy($image->res);
$image->res = $res;
$image->info['width'] = $width;
$image->info['height'] = $height;
return true;
}
This is solve issue with background color when cropping.
Comments
Comment #1
drewish commentedrolled these changes as a patch to make review easier... after pulling some of the changes that were made in 1.1 and the more i look at this the less sense it makes...
Comment #2
dopry commented@murz: yes, because we're doing a canvas resize action.... which is what crop does currently. Are you saying x/y needs normalizing to a grid starting with 0,0? Is this the best solution or should it happen in imageapi_crop? maybe a .test to help understand the problem?
Comment #3
drewish commentedhere's a re-roll.
Comment #4
drewish commentedI committed #396924: Backport fixes from D7 core. Could you review the -dev release and see if this problem persists? If so please re-open the issue.