Page 1 of 1
GD Outputting JPEG as BMP
Posted: Tue Nov 23, 2004 3:37 am
by gv_walker
Hi,
I developed a site which allows a user to upload a file to the server, the server then created a thumbnail image of the file (resize) and a new standard sized image of the file. However when I test it on the actual server, a Linux server using PHP 4 the imagejpeg() function outputs a bitmap file instead of a jpeg!!
I am testing on a Windows server running Apache and PHP 5.
Would the case of the function name make a difference?
Any comments would be a great help.
(Will post code tomorrow)
Thx
Grant
Posted: Tue Nov 23, 2004 5:03 am
by Maugrim_The_Reaper
Starting with the original image - how are you loading that into your PHP script?
e.g. if a BMP is uploaded, are you using imagecreatefromwbmp()? This may matter a great deal - difficult to create a jpeg from a BMP, which may cause the library to default to the original image format - BMP - and output in that same format. This is just a theory however...
Main point to to create from the original format - do your resizing, etc. and create to the new format you need.
The simplest of examples from php manual:
Code: Select all
<?php
// File and new size
$filename = 'test.jpg';
$percent = 0.5;
// Content type
header('Content-type: image/jpeg');
// Get new sizes
list($width, $height) = getimagesize($filename);
$newwidth = $width * $percent;
$newheight = $height * $percent;
// Load
$thumb = imagecreate($newwidth, $newheight);
// need to set this to imagecreatefromXXX, where X is the original image
// format - grabbing the file extension and using this as the basis for a
// switch statement springs to mind
$source = imagecreatefromjpeg($filename);
// Resize
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
// Output
imagejpeg($thumb);
?>
Presumably you're saving the thumbnails - so remove the content-type, and set imagejpeg() to save to a file.
GD creating BMP from JPEG
Posted: Tue Nov 23, 2004 5:29 am
by gv_walker
Hi
Maugrim_The_Reaper,
Thanx for the quick reply!
I don't have the code with me at the moment (I'm at work in South Africa). However I do remember that I did load the image (which is a JPEG in all cases) with the createimagefromjpeg() function. I then create a truecolor image instance and resize and copy it into that (so that I don't lose any color depth). It just doesn't seem to make any sense to me. I test it on my server and everything runs perfectly, but as soon as I put it onto the target server something wierd happens
Thanks for your trouble.
Grant
Posted: Tue Nov 23, 2004 5:52 am
by Maugrim_The_Reaper
Blame the target server...
If it works on your test server - the code should be fine in that case. By chance do you know if the other server is running a recent PHP version? Could be a bug from an older GD2 version or something.