0

I want to add qualit=80 to my upload images file... but no success :(

That' my code:

<?php
// Set limit image size                                   
$limitFileSize=300000;
// Set thumbnail-height to xxx in pixels                                    
$imageheight=250; 
  if($peoplef_id=='0'){
    $query  = "SELECT * FROM peoplef WHERE emailzugang='$emailzugang1'  ";
 $result = mysql_query($query);
 while($row = mysql_fetch_array($result, MYSQL_ASSOC)){$peoplef_id=$row['id'];};
  }
if($peoplef_id!='0'){
uploadPic("pic1",$peoplef_id,$limitFileSize);
uploadPic("pic2",$peoplef_id,$limitFileSize);
uploadPic("pic3",$peoplef_id,$limitFileSize);
uploadPic("pic4",$peoplef_id,$limitFileSize);
uploadPic("pic5",$peoplef_id,$limitFileSize);
uploadPic("pic6",$peoplef_id,$limitFileSize);
uploadPic("pic7",$peoplef_id,$limitFileSize);
uploadPic("pic8",$peoplef_id,$limitFileSize);
}
function uploadPic($PicName,$itemsID,$limitFileSize)
{
 //if($_FILES[$PicName]['size'] > 0 && $_FILES[$PicName]['size'] < $limitFileSize )
 //{
 if($_FILES[$PicName]['size'] > 0  )
 {

 $fileName = $_FILES[$PicName]['name'];
 $tmpName  = $_FILES[$PicName]['tmp_name'];
 $fileSize = $_FILES[$PicName]['size'];
 $fileType = $_FILES[$PicName]['type'];
$imgsize = GetImageSize($tmpName);
    $widthWanted=$imgsize[0];
    $heightWanted=$imgsize[1];
    /*== check size  0=width, 1=height ==|| ($imgsize[1] > 200)    */
    if (($imgsize[0] > 650) ) 
    {
    $widthWanted=2000;
    $heightWanted=ceil((1600/$imgsize[0])*$imgsize[1]);
    }
 echo $widthWanted;
echo "-----";
echo $heightWanted;
 $array=array();
echo "<pre>";
$current_file=$tmpName;
$thumb_name="TempUploadImg/".$PicName.$itemsID.".jpg";
exec("convert ".$current_file." -resize $widthWantedx$heightWanted ".$thumb_name, $array); 
echo "<br>".print_r($array)."<br>"; 
echo "</pre>";
$fp      = fopen($thumb_name, 'r');
 $content = fread($fp, filesize($thumb_name));
 $content = addslashes($content);
 fclose($fp);
 if(!get_magic_quotes_gpc())
 {
 $fileName = addslashes($fileName);
 }
 $picnum=$PicName;
 $query = "INSERT INTO uploadf (peoplef_id, picnum, name, size, type, content ) ".
 "VALUES ('$itemsID', '$picnum', '$fileName', '$fileSize', '$fileType', '$content')";
 //delete("test.jpg");
 mysql_query($query) or die('Error, query failed'); 

 echo "<br>Filee ". basename( $fileName). " uploaded<br><br>";
 }
 //else
 //{    
 ///   if($_FILES[$PicName]['size'] > 0){
 // $fileName = $_FILES[$PicName]['name'];
 // echo "<br><font color=red> File limit Size is $limitFileSize  ; canot uploaded $fileName  </font><br>";
 //   }
 //}
}
?>
  • 2
    just paste the snippet of the code, it's more relevant for people looking at the question, especially if your link becomes invalid at a later date – TommyBs Nov 08 '12 at 11:51
  • Tommy thanks... I tried to add snippet, but it didn't work. Maybe you can add my code from the link and to add it...? – user1741822 Nov 08 '12 at 12:27
  • [Please, don't use `mysql_*` functions in new code](http://stackoverflow.com/q/12859942). They are no longer maintained and the deprecation process has begun, see the [red box](http://php.net/mysql-connect). Learn about [prepared statements](http://en.wikipedia.org/wiki/Prepared_statement) instead, and use [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli); [this article](http://php.net/mysqlinfo.api.choosing) will help you decide which. If you choose PDO, [here is a good tutorial](http://wiki.hashphp.org/PDO_Tutorial_for_MySQL_Developers). – Geek Num 88 Nov 17 '12 at 00:33

1 Answers1

0

Actually this is an Imagemagick question because the resize is done using Imagemagick.

According to the documentation, to set quality when writing JPEG you set -quality, so you need to change the code like this:

exec("convert ".$current_file." -resize $widthWantedx$heightWanted -quality 80 ".$thumb_name, $array);
AndreKR
  • 32,613
  • 18
  • 106
  • 168