Commit 9cac2dd7 authored by Francois Marier's avatar Francois Marier
Browse files

artefact/file/image: maintain image type when resizing (bug #495234)

The image resizing code used to convert all images to PNG. This would
cause problems in certain cases when browsers only looked at the extension
to figure out the file type.

For example, exporting a view containing a resized JPG file would create a
PNG file with a .jpg extension. Using IE on Windows to display the exported
page would file as the mime/type was inferred from the extension.
Signed-off-by: default avatarFrancois Marier <>
parent a9cb4b01
......@@ -455,15 +455,18 @@ function get_dataroot_image_path($path, $id, $size=null) {
$imageinfo = getimagesize($originalimage);
$originalmimetype = $imageinfo['mime'];
$format = 'png';
switch ($originalmimetype) {
case 'image/jpeg':
case 'image/jpg':
$format = 'jpeg';
$oldih = imagecreatefromjpeg($originalimage);
case 'image/png':
$oldih = imagecreatefrompng($originalimage);
case 'image/gif':
$format = 'gif';
$oldih = imagecreatefromgif($originalimage);
case 'image/bmp':
......@@ -521,7 +524,8 @@ function get_dataroot_image_path($path, $id, $size=null) {
//imagecopyresized($newih, $oldih, 0, 0, 0, 0, $newdimensions['w'], $newdimensions['h'], $oldx, $oldy);
$result = imagepng($newih, $resizedimagefile);
$outputfunction = "image$format";
$result = $outputfunction($newih, $resizedimagefile);
if ($result) {
return $resizedimagefile;
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment