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.

CommentFileSizeAuthor
#3 imageapi_258315.patch889 bytesdrewish
#1 imageapi_258315.patch1.13 KBdrewish

Comments

drewish’s picture

Version: 5.x-1.0 » 6.x-1.x-dev
Status: Active » Needs work
StatusFileSize
new1.13 KB

rolled 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...

dopry’s picture

@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?

drewish’s picture

Status: Needs work » Needs review
StatusFileSize
new889 bytes

here's a re-roll.

drewish’s picture

Status: Needs review » Fixed

I 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.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.