How can I add an image next to another

  • xmsmmgrs
  • Beginner
  • Beginner
  • xmsmmgrs
  • Posts: 50

Post 3+ Months Ago

I want to put two ore more images together (in a line) using php. How can I do that?
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8388
  • Loc: USA

Post 3+ Months Ago

PHP Code: [ Select ]
echo '<img src="img.png" alt="alternative" /><img src="img2.png" alt="alternative2" />';

Does that answer your question or did you have something else in mind?
  • xmsmmgrs
  • Beginner
  • Beginner
  • xmsmmgrs
  • Posts: 50

Post 3+ Months Ago

That would be extremely easy, but I need to make it a big image. I was playing with imagecopymerge but could not find a way to put images one next to another. I will have 5 images to put one next to another and one under these.
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8388
  • Loc: USA

Post 3+ Months Ago

So, you want to merge the images into one image? Kinda use GD? Image manipulation?
  • xmsmmgrs
  • Beginner
  • Beginner
  • xmsmmgrs
  • Posts: 50

Post 3+ Months Ago

Yup, users will select the images and the php code will have to merge them, make a big one that people can save on their computer.
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8388
  • Loc: USA

Post 3+ Months Ago

Well... I'm trying a few things and nothing seems to work so far... maybe someone else, more knowledgeable in GD would be able to help you before I stumble against something that works :)
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8388
  • Loc: USA

Post 3+ Months Ago

Well, I got a sample thing to work... But to make it work the way you want it, it would take a while of figuring out how to code it and how to make it implement your idea...

The sample code for the sample thing is...
PHP Code: [ Select ]
<?php
$aa = imagecreatetruecolor(240, 120);
$normal = imagecreatefrompng('image3.png');
$dd = imagecreatefromjpeg('image4.JPG');
 
// Switch antialiasing on for one image
imageantialias($aa, true);
 
imagecopymerge($aa, $dd, 0, 0, 0, 0, 120, 120, 100);
 
imagecopymerge($aa, $normal, 120, 0, 0, 0, 120, 120, 100);
 
// Output image
header('Content-type: image/png');
 
imagepng($aa);
imagedestroy($aa);
imagedestroy($normal);
?>
  1. <?php
  2. $aa = imagecreatetruecolor(240, 120);
  3. $normal = imagecreatefrompng('image3.png');
  4. $dd = imagecreatefromjpeg('image4.JPG');
  5.  
  6. // Switch antialiasing on for one image
  7. imageantialias($aa, true);
  8.  
  9. imagecopymerge($aa, $dd, 0, 0, 0, 0, 120, 120, 100);
  10.  
  11. imagecopymerge($aa, $normal, 120, 0, 0, 0, 120, 120, 100);
  12.  
  13. // Output image
  14. header('Content-type: image/png');
  15.  
  16. imagepng($aa);
  17. imagedestroy($aa);
  18. imagedestroy($normal);
  19. ?>

$aa is the background, $normal is one of the images and $dd is another image that would be put to the side.

Both of those images coded in to be 120px by 120px (Width and height are both 120px).

I don't know if this helps you in your case but... here's this :lol:
  • xmsmmgrs
  • Beginner
  • Beginner
  • xmsmmgrs
  • Posts: 50

Post 3+ Months Ago

OK, that worked, thank you very much! Now how do I add more then two images per line?
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8388
  • Loc: USA

Post 3+ Months Ago

How many are you thinking of? Are they all of consistent sizes?

What I'm doing with that code is creating a background image of one color the width and height of the images that would be resulted after they would be merged into one image.

Like let say that if you put three images together it would have the width of 600 px and the height would be 300 px. Then the background image created should be 600x300.

Then you add the images on that background side by side until they are all at each other sides.

If you'd like and when I get the time, I could write you the class to do this easily... when it does all the math automatically... I got a little plan going in my head for this...
  • xmsmmgrs
  • Beginner
  • Beginner
  • xmsmmgrs
  • Posts: 50

Post 3+ Months Ago

I have managed to write the code, I'll show you the result once I have the site up. Thank you for your help!
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8388
  • Loc: USA

Post 3+ Months Ago

Alright! Good to read :D Your welcome

Post Information

  • Total Posts in this topic: 11 posts
  • Users browsing this forum: No registered users and 55 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.