Hi,
I've had an image upload script running for a client for years. The images are resized by the server to 250 pixels wide. It has worked fine until recently.
The images are now being processed to a far lower quality than before, and losing their€ colour properties.
I think the issue is in my function resize_image();
Any help greatly appreciated!
Here are my file upload functions (they were built from a german upload code hence the messy variable names):
function fileUpload($tmp_name,$file_name,$abpath,$debug)
{
if(!$abpath){$abpath = "/home/httpd/vhosts/domain.com/httpdocs/photosDB/";}
$pathfilename = "$abpath$file_name";
echo"pathfilename = $pathfilename<br>";
if($debug = 1) {echo"File_name = $file_name<br>File tmp name = $tmp_name<br>Path is $abpath<br>";}
if(move_uploaded_file ($tmp_name, $pathfilename))
{
echo"$file_name ($tmp_name) successfully uploaded to $pathfilename<br>";
chmod($pathfilename, 0644);
echo"Chmod successful"; }
}
function resize_image($image_name, $new_width, $newname, $abpath, $newpath, $debug){
$PicPathIn = $abpath;
$PicPathOut = $newpath;
// Picture
$bild="$image_name";
// fileprefix
$tn=$prefix;
$neueBreite=$new_width; //New width
$size=getimagesize("$PicPathIn"."$bild");
$breite=$size[0];
$hoehe=$size[1];
$neueHoehe=intval($hoehe*$neueBreite/$breite);
if($size[2]==2) {
// JPG
$altesBild=ImageCreateFromJPEG("$PicPathIn"."$bild");
$neuesBild=ImageCreate($neueBreite,$neueHoehe);
ImageCopyResized($neuesBild,$altesBild,0,0,0,0,$neueBreite,$neueHoehe,$breite,$hoehe);
$bild2 = $newname;
ImageJPEG($neuesBild,"$PicPathOut$bild2",95);
}
if($debug==1){
echo "Old Picture: <BR>";
echo "<IMG SRC=\"../images/2.0/tempup/$bild\" WIDTH=\"$breite\" HEIGHT=\"$hoehe\">
<BR><BR>";
echo "New Picture:<BR>";
echo "<IMG SRC=\"../images/2.0/$bild2\" WIDTH=\"$neueBreite\" HEIGHT=\"$neueHoehe\">";
}
// close function resize_image
echo"Image $bild2 created and resized to width $neueBreite<br>";
}
//***************************************************************************
function delete_image($img_name,$abpath,$debug){
if(file_exists("$abpath/$img_name"))
{
unlink("$abpath/$img_name");
echo"File $img_name deleted<br><br>";
}else{echo"File $img_name doesn't exists, cannot delete<br><br>";}
}