【问题标题】:How to load and repeat-x an image with php gd?如何使用 php gd 加载和重复-x 图像?
【发布时间】:2010-10-30 20:01:34
【问题描述】:

假设我有一个宽度为 1 像素、高度为 40 像素的图像。 我想加载它,让我们说 imagecreatefrompng 并想 x 重复它,就像 css repeat-x 一样。

PHP GD 可以做到这一点吗?

【问题讨论】:

    标签: php gd repeat imagecreatefrompng


    【解决方案1】:

    你必须指定输出图像的宽度,我选择了1024来演示:

    $srcfile = 'bg.jpg';
    $outfile = 'background.jpg';
    list($src_w,$src_h,$src_type) = getimagesize($srcfile);
    
    $out_w = 1024;
    $out_h = $src_h;
    
    $src = imagecreatefromjpeg($srcfile);
    $out = imagecreatetruecolor($out_w, $out_h);
    
    $curr_x = 0;
    while($curr_x < $out_w){
        imagecopy($out, $src, $curr_x, 0, 0, 0, $src_w, $src_h);
        $curr_x += $src_w;
    }
    
    imagejpeg($out, $outfile, 100);
    imagedestroy($src);
    imagedestroy($out);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-10-14
      • 2011-09-28
      • 2010-12-11
      • 1970-01-01
      • 2012-10-27
      • 1970-01-01
      相关资源
      最近更新 更多