0

I'm using FPDF with PHP to add an image to a PDF and I want to put automatically the size of the image I find this function

    function fctaffichimage($img_Src, $W_max, $H_max) {

 if (file_exists($img_Src)) {
   $img_size = getimagesize($img_Src);
   $W_Src = $img_size[0]; // largeur source
   $H_Src = $img_size[1]; // hauteur source
   if(!$W_max) { $W_max = 0; }
   if(!$H_max) { $H_max = 0; }
   $W_test = round($W_Src * ($H_max / $H_Src));
   $H_test = round($H_Src * ($W_max / $W_Src));
   if($W_Src<$W_max && $H_Src<$H_max) {
      $W = $W_Src;
      $H = $H_Src;
   } elseif($W_max==0 && $H_max==0) {
      $W = $W_Src;
      $H = $H_Src;
   } elseif($W_max==0) {
      $W = $W_test;
      $H = $H_max;
   } elseif($H_max==0) {
      $W = $W_max;
      $H = $H_test;
     }
    elseif($H_test > $H_max) {
      $W = $W_test;
      $H = $H_max;
   } else {
      $W = $W_max;
      $H = $H_test;
   }
 }    
}

but when i do

// requĂȘte
$tab1 = $_GET['tab1'];
$ID = $_GET['ID'];
$table = $_GET['table'];
$ree = "SELECT title,title2 FROM $tab1 WHERE $table = $ID ORDER BY 1";

$sql2 = mysql_query($ree);



// on affiche les deux images avec la fontion fctaffichimage


while ($roww = mysql_fetch_assoc($sql2))
        {

            $nomm = $roww["title"];
            $url = "/var/www/images/".$nomm ;
            fctaffichimage($url,100,100 );
            $pdf->Cell(40,6,'',0,0,'C',$pdf->Image($img_Src,85,55));

        }

it didn't work I try to change the position of $url = "/var/www/images/".$nomm ; fctaffichimage($url,100,100 ); but it didn't work too.

Manuel Allenspach
  • 12,467
  • 14
  • 54
  • 76

1 Answers1

0

I see something I hope to help you. Put at the bottom of the function fctaffichimage the next code:

$img1 = imagecreatefrompng($img_Src);
$img2 = imagecreatetruecolor($W, $H);
imagecopyresampled($img2, $img1, 0, 0, 0, 0, $W, $H, $W_Src, $W_Src);
imagepng($img2, $img_Src);

Here I put a PNG image, but you can generalize it, depends of you need. It's running in my enviroment with PHP 5.3 (but there's a new imagescale function in PHP 5.5).

Migol
  • 8,161
  • 8
  • 47
  • 69
ucmf
  • 1