If you upload a bitmap (*.bmp) file it is not resized, and appears full-size even for thumbnails. Need to do one of the following:

  • Convert to jpeg and carry on
  • Handle bmp files correctly
  • Disallow upload of bmp files altogether

Comments

benshell’s picture

Category: bug » feature
Priority: Normal » Minor
xeniac’s picture

i take Option C: Display a Message that Windows BMP is not supportet.
I never tried to upload Images other to GIF, JPG, and PNG, but now i was curios:
Uploading an XPM Icon shpws me the following Message:
# Uploaded file is not a valid image

Uploading an BMP image brought me the following Messages:
# Unable to create thumbnail image
# Unable to create preview image

As Far as i know gd2 could support Windows BMP and XPM (depends on your installation), but what kind of browser supports them?

The Bug is in the image_get_info() function.
Not in the Image Module.
The Function should be fixed to return false, when the image is not jpeg,gif,or png and image module should say
"Please only upload images in gif, jpeg, or png Format".

t3knoid’s picture

Version: 6.x-1.x-dev » 4.6.x-1.x-dev

I noticed this problem early in my installation of drupal, but promptly ignored because it wasn't really impacting my site. However, not long did it became an annoyance when users kept trying to upload bmp files.

I think it makes more sense to put the fix in image.module instead of the core file image.inc. I am using 4.60. I basically added one line and modified an if statement in image_validate.

> $imageprop = image_get_info($file->filepath);
> if ((!$imageprop) || ($imageprop[extension] <> 'jpg')) {

The first line puts the return value image_get_info in a variable. Using this new variable, we can now check for the type of extension to look out for. In my case, I only wanted JPG so it was a simple change in logic in the subsequent if statement. I am only going to post the modified function here. I think the change is simple enough that everyone can follow my mods.

Using this example, you can also limit the image resolution by checking the width and height items. Maybe someone can mod the image.module settings to include these as user-definable parameters. Anyway, I hope this helps out. Here's the modified code:

function image_validate(&$node, $field_name) {
if (is_null($field_name)) {
$field_name = 'image';
}
if ($file = file_check_upload($field_name)) {
$file = file_save_upload($field_name, _image_filename($file->filename, NULL, TRUE));
if ($file) {
$imageprop = image_get_info($file->filepath);
if ((!$imageprop) || ($imageprop[extension] <> 'jpg')) {
form_set_error($field_name, t('Uploaded file is not a valid image'));
return;
}
}
else {
return;
}
$node->file = $node->images['_original'] = $file->filepath;
_image_build_derivatives($node, true);
}
}

geodaniel’s picture

Version: 4.6.x-1.x-dev » 6.x-1.x-dev
Category: feature » bug

It would be nice to have this working out of the box.

As for changing the status, I suspect it's still an issue with HEAD though I must admit I've only tried it up to 4.7, and this is a bug - either a bug that .bmp files are allowed to be uploaded even though they can't be modified, or simply that they are not being resized.

Going forward, I'd suggest we check to see if there is an image library installed that can cope with bitmaps; if there is, convert the image to a JPG and continue normally; if there isn't, disallow the upload of .bmp images.

drewish’s picture

Status: Active » Closed (won't fix)

yeah BMP isn't supported. you'll find that in the current versions you cannot upload BMP files.

geodaniel’s picture

Thanks for the update drewish, that's a good enough fix for me - looks like it's time to update to the latest version :)

Jürgen Depicker’s picture

Status: Closed (won't fix) » Active

But I'm unhappy with the solution 'won't fix'. I made an intranet application based on Drupal, and it is essential for us to be able to upload BMP's, tif's or whatever, since we're into vision technology and jpg's sometimes just don't do the trick.
I'll have a look to see if I can get this fixed, but would welcome other's remarks as well.

drewish’s picture

Status: Active » Closed (won't fix)

then you need to treat them as attachments not files to be viewed by the browser. without plugins, png, gif and jpg are the formats supported by most browsers and drupal core.

jonahan’s picture

Status: Closed (won't fix) » Postponed (maintainer needs more info)

Ok, so what is the final word? By default with imagefield, I can upload .bmp and .pdf - something I don't want users to be doing if the images can't be handled by imagecache later.

If we want Drupal to become a good system, developers need to start including/fixing basic things like this that most users will be doing.

jonahan’s picture

FYI, here is my hack - in case it helps someone:

In imagefield.module, go to "function imagefield_widget" (line 368).

Down towards the very bottom of this function is this:


case 'validate':
if ($field['required']) {
if (!count($node_field)) {
form_set_error($fieldname, $field['widget']['label'] .' is required.');
}
}

Directly after that, I have this:

      $mime = $node_field[0][filemime];
      $explodered = explode('/', $mime);
      if($explodered[1] == 'bmp')
      	form_set_error($fieldname, 'File cannot be a bitmap (.bmp).  Only .jpg, .gif and .png please.');
      if($explodered[1] == 'pdf')
      	form_set_error($fieldname, 'File cannot be a PDF (.pdf).  Only .jpg, .gif and .png please.');

Yes, it's dumb but it works. :D Sometimes simple is better.

drewish’s picture

you realize you're replying to and *image* issue not an *imagefield* issue right?

drewish’s picture

Status: Postponed (maintainer needs more info) » Closed (won't fix)