【发布时间】:2010-10-30 20:01:34
【问题描述】:
假设我有一个宽度为 1 像素、高度为 40 像素的图像。 我想加载它,让我们说 imagecreatefrompng 并想 x 重复它,就像 css repeat-x 一样。
PHP GD 可以做到这一点吗?
【问题讨论】:
标签: php gd repeat imagecreatefrompng
假设我有一个宽度为 1 像素、高度为 40 像素的图像。 我想加载它,让我们说 imagecreatefrompng 并想 x 重复它,就像 css repeat-x 一样。
PHP GD 可以做到这一点吗?
【问题讨论】:
标签: php gd repeat imagecreatefrompng
你必须指定输出图像的宽度,我选择了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);
【讨论】: