patch imagemagick to validate files without an extension

Created on 13 March 2024, 8 months ago

Recently I updated to D7.100 and image uploads stopped working. Image file paths being sent to image_imagemagick_get_info() no longer include the extension in the file name so validation of the file type failed. I altered image_imagemagick_get_info() to fall back to the mime type in this case. The new code for that function is

function image_imagemagick_get_info(stdClass $image) {
  $details = FALSE;
  $data = _imagemagick_getimagesize(drupal_realpath($image->source));

  if (isset($data) && is_array($data)) {
    $extension = pathinfo($image->source, PATHINFO_EXTENSION);
    if($extension == '' && !empty($data['mime'])) {
      $parts = explode('/', $data['mime']);
      if (count($parts) === 2) {
        $extension = end($parts);
      }
    }
    $details = array(
      'width'     => $data[0],
      'height'    => $data[1],
      'extension' => $extension,
      'mime_type' => $data['mime'],
    );
  }

  return $details;
}
🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇳🇿New Zealand rimu

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024