I recently noticed that when uploading transparent user pictures to a Drupal site, the transparent colour is lost (replaced with black). I think its to do with image_size()... but I noticed the slightly odd logic in user.module:

 if (!$info || !$info['extension']) {
    form_set_error('picture', t('The uploaded file was not an image.'));
  }
  else if (image_get_toolkit()) {
    image_scale($file->filepath, $file->filepath, $maxwidth, $maxheight);
  }
  else if (filesize($file->filepath) > (variable_get('user_picture_file_size', '30') * 1000)) {
    form_set_error('picture', t('The uploaded image is too large; the maximum file size is %size kB.', array('%size' => variable_get('user_picture_file_size', '30'))));
  }
  else if ($info['width'] > $maxwidth || $info['height'] > $maxheight) {
    form_set_error('picture', t('The uploaded image is too large; the maximum dimensions are %dimensions pixels.', array('%dimensions' => variable_get('user_picture_dimensions', '85x85'))));
  } 

So, the image is always scaled if an image toolkit is found. The attached patch only scales user pictures if they are too large, and will still show an error if a toolkit is not found.

I'm aware that there may be a better patch for image.inc to retain scaled image transparency?

Comments

pfaocle’s picture

Version: 4.6.1 » x.y.z

Still applies to head.

praseodym’s picture

And the description texts say you may not upload a picture larger than that. I even think the size of the resized picture isn't checked...

Steve Dondley’s picture

Status: Needs review » Needs work

First, I couldn't reproduce the problem in CVS using the GD toolkit.

Second, the logic in this patch is flawed. If an image is less than the max. width/height but greater than the file size limit, it will not get resized.

Third, there is a proposed patch in the works at http://drupal.org/node/27234 that would make toolkits mandatory. That patch would supersede this patch.

pfaocle’s picture

Status: Needs work » Fixed

Can't reproduce with clean install of latest CVS. Marking fixed?

Stefan Nagtegaal’s picture

I thionk this depends on what kind of image your trying to upload which is resized. .gifs will probablt keep their transparency, but .png's with (partial) transparency will probably get screwed up.

(Keep in mind that I mean they are getting resized with GD, and *not* with ImageMagick.)
There is a fix to this issue, but it requires a lot of code. (About 100 lines, for only implementing rspecting transparency in png's)..

Anonymous’s picture

Status: Fixed » Closed (fixed)