duandi8544 2015-05-26 18:29
浏览 176
已采纳

TCPDF图像宽高比问题

I have an issue with TCPDF Image inserting.

enter image description here

Here's the code i'm using :

$this->Image($this->data['logo'], PDF_MARGIN_LEFT, 5, 60, 20, '', '', 'M', true);

I've set the resize at true, but the TCPDF library do not respect image ratio.

How can I force preserving image ratio ?

For information I'm using TCPDF 6.2.8 (2015-04-29).

Thanks for your support, David.

  • 写回答

2条回答 默认 最新

  • douyan1944 2015-05-27 08:35
    关注

    Here's the solution I found :

        if ('' != $this->data['logo'] && is_file($this->data['logo'])) {
            // select only one constraint : height or width. 60x20 image emplacement => ratio = 3 (60/20)
            list($image_w, $image_h) = getimagesize($this->data['logo']);
            if (3 > $image_w / $image_h) list($w, $h) = array(0, 20);
            else list($w, $h) = array(60, 0);
    
            $this->Image($this->data['logo'], PDF_MARGIN_LEFT, 5, $w, $h, '', '', 'M');
        }
    

    I've found the image emplacement ratio (60/20=3), I compared it to the image ratio and I choose between set the width or the heigh.

    Thanks to JamesG to help me to find my solution.

    David.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大