views:

18

answers:

2

Suppose i have an image with width 1px and height 40px. I want to load it with lets say imagecreatefrompng and want to x-repeat it, just like css repeat-x.

Is this possible with PHP GD?

A: 

Refer link :

http://www.php.net/manual/en/ref.image.php

I hope it will help u.

seed_of_tree
helped me too, thanks a lot.
Ioannis
A: 

You have to specify width of output image, I have chosen 1024 to demonstrate:

$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);
dev-null-dweller
thank you man, it really helped me....
Ioannis