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条)

报告相同问题?

悬赏问题

  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题