Windows-bitmaps will not be resized by imagefield. There's no setting like "allowed image types". You can e. g. destroy any layout by uploading an oversized BMP-Image. Affected versions (tested): 5.x-1.1 to 5.x-2.x-dev.

Comments

baja_tz’s picture

Same problem. Imagefield maximum resolution 400x400, also have imagecache 2 presets: 300x300, 100x100. When I try to upload .bmp file: 1200x1596 size: 5.7MB, after while, image is uploaded, no resizing at all. Thanks for help.
imagefield 5.x-1.1
CCK 5.x-1.6-1
Sorry, works in 5.x-2.x-dev, just doesn't display warning message if i in both fields (have 2 single value imagefields) put bmp's.

jsethi’s picture

Title: .bmp uploads possible, no resizing - could destroy layout. » .bmp uploads possible, no resizing - could destroy layout. (Need filetype restriction)

Im having the same problem. Wish I knew a way to restrict the file types.

The BMP images are not resized. I am using ImageCache for resizing.

jsethi’s picture

Im having the same issue.

Need a way to restrict file types.

baja_tz’s picture

Don't want to be boring, but it's possible to change extension from bmp to jpg, then image pass through without resizing.
imagefield 5.x-2.x

baja_tz’s picture

Possible solution:

  if (strpos($file['filemime'], 'image/') !== 0 || strpos($file['filemime'], 'image/bmp') === 0 ) {
    // sorry no it isn't. do not pass go, do not collect $200.
    form_set_error($field['field_name'], t('Mime Type mismatch. Only image files with extension: %allowed_extensions may be upload. You      uploaded a file with mime type: %mime', array('%mime' => $file['filemime'], '%allowed_extensions' => $field['widget']['file_extensions'])));
    $valid = FALSE;
  }

So far works for me.

JStarcher’s picture

what's the deal with the $field['widget']['file_extensions']? Where is that from?

Also, how are you passing passing this? I used hook_nodeapi() on the validate op....

lias’s picture

Version: 5.x-1.1 » 5.x-2.0-rc2

I've just installed release candidate 2 and had the same issue with a bmp file that was way too large (didn't retain the size I had input for the imagefield) for the layout. I was wondering too if there was someplace to limit the file types accepted, like filefield does? I only want users to be able to upload png, gif and jpg.

I'm using:

Content 5.x-1.6-1
Private downloads
Image Field 5.x-2.0-rc2
Drupal 5.5

I would also like to know where the above code was inserted if in fact fixes this problem.
Thanks.

baja_tz’s picture

It's on line 776. Original:
if (strpos($file['filemime'], 'image/') !== 0) {
Try to add:
if (strpos($file['filemime'], 'image/') !== 0 || strpos($file['filemime'], 'image/bmp') === 0 ) {
This solution is only temporary, because it's unreliable. There is lot stuff written about it. You might want to read this:
http://www.jellyandcustard.com/2006/01/19/php-mime-types-and-fileinfo/

m3avrck’s picture

subscribe, having the same issue

drubage’s picture

Also subscribing. Where does the resize occur in the code? I have seen bmp extensions written for the php image resizing tool. Maybe we can add one of them to the code? I need to see where it happens though to be sure.

-Drew

leokyle’s picture

Subscribing, same issue.

JStarcher’s picture

I used that code in my custom module inside hook_nodeapi()

function mycustommodule_nodeapi(&$node, $op) {
  global $user;

  switch ($op) {
    case 'validate':
      switch ($node->type) {
        case 'image':
          $size = getimagesize($node->field_image[0]['filepath']);
          if ($size[0] > 1000 || $size[1] > 700) {
            image_scale($node->field_image[0]['filepath'], $node->field_image[0]['filepath'], 1000, 700);
          }

          if ($node->field_image[0]['filesize'] > 2097152) {
            form_set_error('image', t('The image is too large to upload. Please upload a smaller image.'));
            $not_valid = TRUE;
          }

          if (strpos($node->field_image[0]['filemime'], 'image/') !== 0 || $node->field_image[0]['filemime'] == 'image/bmp') {
            form_set_error('image', t('Invalid filetype. Only image files with extension: %allowed_extensions may be upload. You uploaded a file with type: %mime', array('%mime' => $node->field_image[0]['filemime'], '%allowed_extensions' => 'jpg, jpeg, gif, png')));
            $not_valid = TRUE;
          }

          if ($not_valid) {
            unset($node->field_image, $_SESSION['imagefield']);
            file_delete($node->field_image[0]['filepath']);
            drupal_goto('node/add/image');
          }
          break;
      }
      break;
  }
}

Works great. Hope this helps!

lias’s picture

Sorry but I don't understand where this code should be used? Is it inserted into imagefield.module or template.php ?

leokyle’s picture

Its useful but not a real solution .. i think its gonna be better adding a list of allowed mime types instead of blocking the not allowed ones. i have seen it somewhere before for imagefield...

drubage’s picture

Why isn't the goal here to add the functionality to resize bmp files? Is it completely not possible with PHP? I know it's not part of gd but I think there's a workaround somewhere out there. I've seen some functions like ImageBMP (http://scripts.66c.com/imagebmp-and-imagecreatefrombmp-functions-7216.html) which can resize bmp files and write them to the server.

-Drew

dopry’s picture

Status: Postponed (maintainer needs more info) » Closed (fixed)

Why don't you just remove .bmp from the allowed extensions. It should be able to change it on the field settings form.

lias’s picture

I don't have bmp as an allowed extension and yet a user uploaded one.

Firetracker’s picture

Same issue - anyone got a solution yet?

vitich’s picture

I need it too.
Filetype restriction or something else that will fix it.
P.S. My customer asked me today "what`s wrong with my thumbnails?" Well... :)

--
Victor from Ecovillage Dolyna Djerel

gaele’s picture

Three things:

- the standard GD-library doesn't process BMP files. Imagecache won't resize them, and they will show up at their original size.
- since 5.x-2.0 Imagefield has a setting "Permitted upload file extensions". So you can block BMP files there.
- if you want to accept (and resize) BMP files try the ImageMagick library: http://drupal.org/node/131994

ethanw’s picture

Category: bug » feature

I also had this issue. While small, it renders the module unusable for production sites without modification. The line numbers from #8 weren't quite rigut for me, instead I replaced the code (no php tags in the code, just for syntax highlighting):

if (strpos($file['filemime'],'image') !== FALSE) {

with

    if (strpos($file['filemime'], 'image/bmp') !== FALSE) {
      $edit_url = url('node/' . $node->nid . '/edit');
      drupal_set_message('Please <a href="' . $edit_url . '">go back</a> and choose another image to upload as Windows BMP files are not currently supported','error');
    }
    if (strpos($file['filemime'],'image') !== FALSE && strpos($file['filemime'], 'image/bmp') === FALSE) {