I have what I consider a very simple issue. Currently I have a web site that will allow the user to upload any of several graphic formats, including GIF and PNG. In most cases, I am able to convert the image to a JPG using the standard GD library with PHP.
However Windows BMP files will not convert. I tried the WBMP included with GDlib , but have found out that is something entirely different.
Here is the code that outputs the JPG file:
if (isset($_REQUEST['submit_photo'])) {
$uploadfile = $uploaddir.'photo_'.$_SESSION['user_id'].'.jpg';
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
$i=imagecreatefromfile($uploadfile);
imagejpeg($i, $uploadfile);
} else {
print "<pre>";
print "Error in file upload:\n";
print_r($_FILES);
print "</pre>";
}
}
The function imagecreatefromfile($uploadfile) simply converts the image to a standard GDlib image.
Here it is:
function imagecreatefromfile($filename)
{
static $image_creators;
if (!isset($image_creators)) {
$image_creators = array(
1 => "imagecreatefromgif",
2 => "imagecreatefromjpeg",
3 => "imagecreatefrompng",
6 => "imagecreatefrombmp",
16 => "imagecreatefromxbm"
);
}
$image_size = getimagesize($filename);
if (is_array($image_size)) {
$file_type = $image_size[2];
if (isset($image_creators[$file_type])) {
$image_creator = $image_creators[$file_type];
if (function_exists($image_creator)) {
return $image_creator($filename);
}
} else {
echo "Unknown file type: ".$file_type;
}
}
// "imagecreatefrom...() returns an empty string on failure"
return "";
}
This definatly works for GIF and PNGs, is there anything I can do to get it to work for Windows BMPs also?
Type '6' is the type of file that BMPs return, but unfortunately the function "imagecreatefrombmp" doesn't return a GDimage as I would expect.
I appreciate whatever suggestions you might have.