سؤال

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