I upgraded apache with easyapache. It had me recompile php and upgraded php to 4.31 and gd to v.2.0.
Now all my scripts will only upload images in poor quality -- almost looks like 8 color optimization.
At anyrate here's the function, any ideas would be helpful.
<?php
// Here's the function
function resize($src,$dir,$max) {
$image_stats = GetImageSize($src);
$imagewidth = $image_stats[0];
$imageheight = $image_stats[1];
$file_type = $image_stats[2];
if ($file_type == 2) {//.jpg
$filename = uniqid("") . ".jpg";
if (($imagewidth > $max) || ($imageheight > $max)) {
//image needs resizing
if ($imagewidth >$imageheight ) {
$ratio = ($imageheight / $imagewidth);
$new_w = $max;
$new_h = round($max $ratio);
} else {
$ratio = ($imagewidth / $imageheight);
$new_w = round($max $ratio);
$new_h = $max;
}
$dst_img = imagecreate($new_w,$new_h);
$src_img = ImageCreateFromJPEG($src);
imagecopyresized($dst_img,$src_img,0,0,0,0,$new_w,$new_h,imagesx($src_img),imagesy($src_img));
$new_photo = $dir . $filename;
if (ImageJPEG($dst_img,$new_photo)) {
return $filename;
} else {
return "";
}
} else {
//image doesn't need resizing
$new_photo = $dir . $filename;
if (copy($src,$new_photo)) {
return $filename;
} else {
return "";
}
}
} else {//not a .jpg
return "";
}
}
//here's the code for my ade page
for ($i=1;$i<=$photo_number;$i++) {
$file_name = "photo" . $i . "_name";
$file = "photo" . $i;
$resized = "";
if ($$file_name) {
$resized = resize($$file,$folder,300);
if ($resized) {
$add_image=true;
print "$file uploaded<br>\n";
} else {
$add_image=false;
print "Unable to upload $file<br>\n";
}
} else {
// no file uploaded
print "No file uploaded for Image $i<br>\n";
$add_image=false;
}
?>