Hi all,
I have a script that works wonderfully with uploading an image, resizing it, placing it into a file and calling it out from a database. This has worked for several months.
Now I'm getting bad image quality when I upload that I've never seen before. All of my photos are coming out blue. This sounds stupid, but I didn't touch my script and I can't figure out why the quality is sometimes good and sometimes bad (it's not constant). The files I'm uploading are regular .JPG files, which the script converts to .PNGs.
Here is the script that processes the upload:
<?
If ($btnMain){
$date = date("gismdY");
$rand = rand(1,20);
list(,$type) = split("\.",$_FILES['userfile']['name'],2);
switch($type)
{
case "jpg":
$oldImage=imageCreateFromJPEG($_FILES['userfile']['tmp_name']);
break;
default:
die('Unsupported image type. Please upload .jpg files only.');
}
$image = $oldImage;
$width = imagesx($image);
$height = imagesy($image);
if ($width > 150)
{
$new_width = 150;
$new_height = ($new_width * $height) / $width;
}
else
{
$new_width = $width;
$new_height = $height;
}
$newImage = imagecreate($new_width,$new_height);
imagecopyresized($newImage,$image,0,0,0,0,$new_width,$new_height,$width,$height);
imagePNG($newImage,"../../images/inventory/$date.$rand.png");
move_uploaded_file($_FILES['userfile']['tmp_name'],"../../images/inventory/$date.$rand.$png");
imagedestroy($image);
imagedestroy($newImage);
$query = "UPDATE inventory SET image='../../images/inventory/$date.$rand.png' WHERE ID = $iID";
$result = mysql_query($query);
move_uploaded_file($FileToUpload, "../../images/inventory/$date.$rand.png");
?>
Like I said, the actual process works, but the images are terrible. I noticed while looking at the PNGs that they are being converted to Index Color. Can this be the problem?
Thanks for any help.
Geogal