Pic1 is the uploaded file, I want to watermark it with watermark.gif, then compress it until it's < 102400 bytes, and finally, I want to create a thumbnail of it.
Is there a way to do this, so the script actually works?
if ($pic1!="" AND $pic1!="none")
{
if( $pic1_type == "image/pjpeg" || $pic1_type == "image/jpeg" )
{
copy( $pic1, "mypics/$picnr-1.jpg" );
unlink( $pic1 );
$background = imagecreatefromjpeg("mypics/$picnr-1.jpg");
$insert = imagecreatefromgif("mypics/watermark.gif"); // the size of this watermark is 49x9 pixels
$insert_x = imagesx($background);
$insert_y = imagesy($background);
$inserta_x = $insert_x - 49;
$inserta_y = $insert_y - 9;
imagecopy($background,$insert,$inserta_x,$inserta_y,0,0,$insert_x,$insert_y);
$qual=100;
$bildfilen = "mypics/$picnr-1.jpg";
imagejpeg($background,$bildfilen,$qual);
$bildstorlek = filesize($bildfilen);
while ($bildstorlek > 102400)
{
$qual=$qual-10;
imagejpeg($background,$bildfilen,$qual);
$bildstorlek = filesize($bildfilen);
}
$pc_file_name = "mypics/$picnr-1.jpg";
$pc_old = imageCreateFromJpeg($pc_file_name);
$image_attribs = getimagesize($pc_file_name);
$th_max_width = 70;
$ratio = $th_max_width/$image_attribs[0];
$th_width = 70;
$th_height = $image_attribs[1] * $ratio;
$pc_new = imagecreatetruecolor($th_width,$th_height);
imageAntiAlias($pc_new,true);
$th_file_name = "mypics/$picnr-1sm.jpg";
imageCopyResampled($pc_new,$pc_old,0,0,0,0,$th_width,$th_height, $image_attribs[0], $image_attribs[1]);
imageJpeg($pc_new,$th_file_name,75);
mysql_query( "UPDATE database3 SET pic1='1' WHERE picnr='$picnr'") or errormess( mysql_error() );
}
}
Thank you very much in advance!