Images and PHP

Discussion in 'PHP' started by Nerve, Jul 20, 2007.

  1. #1
    Does anyone know how to take two images and put them side by side?

    Can anyone help me out?

    Thanks.
     
    Nerve, Jul 20, 2007 IP
  2. exodus

    exodus Well-Known Member

    Messages:
    1,900
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    165
    #2
    <img src="img.png"><img src="img.png">
    Code (markup):
    This is more of a html question then a php question.
     
    exodus, Jul 20, 2007 IP
  3. Nerve

    Nerve Peon

    Messages:
    467
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    No, I want to do it in PHP. So the two images are 1 image.
     
    Nerve, Jul 20, 2007 IP
  4. lbalance

    lbalance Peon

    Messages:
    381
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #4
    i usually put them in a table, inside seperate <td>'s but on the same row.
     
    lbalance, Jul 20, 2007 IP
  5. exodus

    exodus Well-Known Member

    Messages:
    1,900
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    165
    #5
    The following will guide you on your path. You will need gd 2.0 enabled with php. Basicly you use gd to create a WIDTHOFIMG1+WIDTHOFIMG2 by HIGHTOFIMG1+HIGHTOFIMG2 blank image. Read in the first image. Read in the second image. Then copy then onto the blank image. Then output the "blank image" dubed loader image.

    http://us2.php.net/manual/en/function.imagecopyresampled.php

    <?php
    function LoadJpeg($imgname)
    {
        $im = @imagecreatefromjpeg($imgname); /* Attempt to open */
        if (!$im) { /* See if it failed */
            $im  = imagecreatetruecolor(150, 30); /* Create a black image */
            $bgc = imagecolorallocate($im, 255, 255, 255);
            $tc  = imagecolorallocate($im, 0, 0, 0);
            imagefilledrectangle($im, 0, 0, 150, 30, $bgc);
            /* Output an errmsg */
            imagestring($im, 1, 5, 5, "Error loading $imgname", $tc);
        }
        return $im;
    }
    header("Content-Type: image/jpeg");
    
    $img = LoadJpeg("bogus.jpg");
    $img2 = LoadJpeg("bogus2.jpg");
    //uncomment the below and edit.
    //$img3loaderimage = imagecreatefromtrue(X,Y);
    
    list($width, $height) = getimagesize("bogus.jpg");
    $new_width1 = $width * $percent;
    $new_height1 = $height * $percent;
    
    list($width, $height) = getimagesize("bogus2.jpg");
    $new_width2 = $width * $percent;
    $new_height2 = $height * $percent;
    
    // Copy the two images onto the loader image. Using X,Y coords for placement.
    imagecopyresampled($img3loaderimage, $img, 0, 0, 0, 0, $new_width1, $new_height1, $width, $height);
    imagecopyresampled($img3loaderimage, $img2, 0, 0, 0, 0, $new_width2, $new_height2, $width, $height);
    
    imagejpeg($img3loaderimage,null,100);
    ?> 
    
    PHP:
     
    exodus, Jul 20, 2007 IP
  6. KalvinB

    KalvinB Peon

    Messages:
    2,787
    Likes Received:
    78
    Best Answers:
    0
    Trophy Points:
    0
    #6
    why are you adding the heights together when they're going side by side?
     
    KalvinB, Jul 20, 2007 IP