문제

I'm trying to tile multiple images, i.e. put one directly underneath another. They all have the same width (120px) and differing heights.

This is what I have:

$finalbg = null;
for($i=0; $i<7; $i++) {
    $addbg = imagecreatefromjpeg('images/left/'.$url[$drawn]);
    $addsize = imagesy($addbg);

    if($finalbg != null) $basesize = imagesy($finalbg); else $basesize = 0;
    $newsize = $addsize+$basesize;

    $newbg = imagecreatetruecolor(120, $newsize);
    if($finalbg != null) imagecopy($newbg, $finalbg, 0, 0, 0, 0, 120, $basesize);
    imagecopy($newbg, $addbg, 0, $basesize, 0, 0, 120, $addsize);
    $finalbg = $newbg;
}

header( "Content-type: image/jpeg" );
imagejpeg($finalbg);

The sizes are outputting correctly, but it keeps telling the image contains errors, and I have no idea why :( Same thing if I try to output addbg or newbg.

Thanks.

도움이 되었습니까?

해결책

Okay, apparently the problem was that there was HTML on the page that was supposed to be rendered, which turns out not to be possible in combination with a GD image.

So I took a different approach. I saved the rendered image as a file, like so:

imagejpeg($finalbg, 'images/left/bg.jpg');

and set it as the background in CSS. And now it works!

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top