【问题标题】:FPDF image sizeFPDF 图像大小
【发布时间】:2014-01-31 14:29:48
【问题描述】:

我正在使用 FPDF 和 PHP 将图像添加到 PDF,我想自动放置图像的大小我找到了这个函数

    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;
   }
 }    
}

但是当我这样做时

// 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));

        }

没用 我尝试改变 $url = "/var/www/images/".$nomm 的位置; fctaffichimage($url,100,100);但它也没有用。

【问题讨论】:

    标签: image fpdf automatic-properties image-size


    【解决方案1】:

    我看到了一些希望对您有所帮助的东西。将下一段代码放在函数 fctaffichimage 的底部:

    $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);
    

    这里我放了一张PNG图像,但你可以概括它,取决于你的需要。它在我的 PHP 5.3 环境中运行(但 PHP 5.5 中有一个新的图像缩放功能)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-09-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-13
      • 1970-01-01
      相关资源
      最近更新 更多