1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Image over image combined on web

Discussion in 'Graphics & Multimedia' started by tomyoung, Aug 19, 2005.

  1. #1
    HI guys

    need some help here, I stuck here for a while now.
    All I am trying to do is to combine image_file1.gif and image_file2.gif (semi transparent)

    bottom layer is image_file1.gif top layer is image_file2.gif

    I could to it with any image editing program, no problem

    The thing is I would like to combine them on a website.

    Let's say an user, choose to combine image 1 (bottom layer) AND then choose image 2 (top layer), one it is submitted, those two files will be combined together and display on a new page.

    I don't know how to do it, anyone who has experienced this situation would be lovely if I can get some tips.

    What script should I use? What technique should I use? May be technology is not supporting yet? I have no Idea.

    Please Please Please help


    Cheers,

    Yanto
    tomyoung, Aug 19, 2005 IP
  2. Willy

    Willy Peon

    Messages:
    281
    Likes Received:
    25
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Hi Tom, and welcome to DP :)

    You can do it server-side with PHP libraries such as GD2, but I think the simplest approach, not to mention the most efficient, would be to just do it on client-side with CSS stylesheets, by stacking the images on top of each other and making the top one transparent or partially translucent. Try Googling for "css image overlay transparent".
    Willy, Aug 19, 2005 IP
  3. tomyoung

    tomyoung Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    HI willy

    Thanks for the advice, I really appreciate it.
    I have just tried the CSS stylesheet one my old friend suggested.

    It turns out that the bottom image is fine, the top image, with gif extension (totally background transparent), once combined the background of the top image becomes white.

    When I tried another file extension using .png for the top image (totally background transparent), once combined the background of the top image becomes grey. I don't know what went wrong, but I will have more trials and errors.

    In the mean time, I will also try with the server side php using GD2 libraries as you suggest, when I have the result I will post again here.

    Anyone please feel free to give some tips

    Many Thanks


    Yanto
    tomyoung, Aug 19, 2005 IP
  4. Willy

    Willy Peon

    Messages:
    281
    Likes Received:
    25
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Remember that Internet Explorer has serious issues with PNG images; that may have been the problem in the second try, if you use IE... :(
    Willy, Aug 19, 2005 IP
  5. nevetS

    nevetS Evolving Dragon

    Messages:
    2,544
    Likes Received:
    211
    Best Answers:
    0
    Trophy Points:
    135
    #5
    Another option is imagemagick - the convert program included as part of the package could easily do what you need. There are perl libraries if you wanted to do it from a cgi or if you wanted to do it from php, you could use shellexec().

    here's some code I wrote a while back - it doesn't do what you need, but it's close enough that you can get the idea of how to put together a command string to run convert.

    My script just writes text on a plain background. I haven't had the need to develop it further, but I wanted to know that I could do it when the time comes to build what I needed.

    This assumes imagemagick is installed in the /usr/bin directory and you have rights to execute. It also assumes you have the same fonts available that I do. If a font doesn't work, try another one. There may be other assumptions. I wrote this a long time ago and didn't comment it very well at all. (I named the script img.php)

    PHP:
    1.  
    2. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    3. <html>
    4. <head>
    5. <title>Text Image Builder</title>
    6. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    7. <?php
    8. $text = $_POST['imagetext'];
    9. $dimensions = $_POST['dimensions'];
    10. $background = $_POST['background'];
    11. $font = $_POST['font'];
    12. $points = $_POST['points'];
    13. $executed = "NO";
    14. $commandstring = "echo \"".$text."\" | /usr/bin/convert -background ".$background." -page ".$dimensions." -font ".$font." -pointsize ".$points." text:- /usr/local/apache/hosts/mysite/images/mg/test.gif";
    15. if (!($text == NULL)){
    16. $executed = "YES";
    17. $output = shell_exec($commandstring);
    18. }
    19. ?>
    20. </head>
    21.  
    22. <body>
    23. <? echo $_POST['imagetext']; ?>
    24. <form action="/img.php" method="post" enctype="application/x-www-form-urlencoded" name="Image Create" target="_self">
    25.   <table width="100%"  border="0" cellspacing="0" cellpadding="0">
    26.     <tr>
    27.       <td>Image Text</td>
    28.       <td><input name="imagetext" type="text" value=<? echo "\"".$text."\""; ?> size="80" maxlength="30"></td>
    29.     </tr>
    30.     <tr>
    31.       <td>Dimensions</td>
    32.       <td><input type="text" name="dimensions" value=<? echo "\"".$dimensions."\""; ?> size="20" maxlength="10"></td>
    33.     </tr>
    34.     <tr>
    35.       <td>Background</td>
    36.       <td><input type="text" name="background" value=<? echo "\"".$background."\""; ?> size="30" maxlength="30"></td>
    37.     </tr>
    38.     <tr>
    39.       <td valign="top">Font</td>
    40.       <td><select name="font">
    41.           <option value="AvantGarde-Book" selected> AvantGarde-Book</option>
    42.           <option value="AvantGarde-BookOblique"> AvantGarde-BookOblique</option>
    43.           <option value="AvantGarde-Demi"> AvantGarde-Demi</option>
    44.           <option value="AvantGarde-DemiOblique"> AvantGarde-DemiOblique</option>
    45.           <option value="Bookman-Demi"> Bookman-Demi</option>
    46.           <option value="Bookman-DemiItalic"> Bookman-DemiItalic</option>
    47.           <option value="Bookman-Light"> Bookman-Light</option>
    48.           <option value="Bookman-LightItalic"> Bookman-LightItalic</option>
    49.           <option value="Courier"> Courier</option>
    50.           <option value="Courier-Bold"> Courier-Bold</option>
    51.           <option value="Courier-Oblique"> Courier-Oblique</option>
    52.           <option value="Courier-BoldOblique"> Courier-BoldOblique</option>
    53.           <option value="Helvetica"> Helvetica</option>
    54.           <option value="Helvetica-Bold"> Helvetica-Bold</option>
    55.           <option value="Helvetica-Oblique"> Helvetica-Oblique</option>
    56.           <option value="Helvetica-BoldOblique"> Helvetica-BoldOblique</option>
    57.           <option value="Helvetica-Narrow"> Helvetica-Narrow</option>
    58.           <option value="Helvetica-Narrow-Oblique"> Helvetica-Narrow-Oblique</option>
    59.           <option value="Helvetica-Narrow-Bold"> Helvetica-Narrow-Bold</option>
    60.           <option value="Helvetica-Narrow-BoldOblique"> Helvetica-Narrow-BoldOblique</option>
    61.           <option value="NewCenturySchlbk-Roman"> NewCenturySchlbk-Roman</option>
    62.           <option value="NewCenturySchlbk-Italic"> NewCenturySchlbk-Italic</option>
    63.           <option value="NewCenturySchlbk-Bold"> NewCenturySchlbk-Bold</option>
    64.           <option value="NewCenturySchlbk-BoldItalic"> NewCenturySchlbk-BoldItalic</option>
    65.           <option value="Palatino-Roman"> Palatino-Roman</option>
    66.           <option value="Palatino-Italic"> Palatino-Italic</option>
    67.           <option value="Palatino-Bold"> Palatino-Bold</option>
    68.           <option value="Palatino-BoldItalic"> Palatino-BoldItalic</option>
    69.           <option value="Times-Roman"> Times-Roman</option>
    70.           <option value="Times-Bold"> Times-Bold</option>
    71.           <option value="Times-Italic"> Times-Italic</option>
    72.           <option value="Times-BoldItalic"> Times-BoldItalic</option>
    73.           <option value="Symbol"> Symbol</option>
    74.         </select>
    75.         &nbsp <input name="points" type="text" value="14" size="10" maxlength="3"></td>
    76.     </tr>
    77.     <tr>
    78.       <td valign="top">&nbsp;</td>
    79.       <td><input type="submit" name="Submit" value="Submit"></td>
    80.     </tr>
    81.   </table>
    82.   </form>
    83.  
    84. <p><? if($executed == "YES") {echo $commandstring."<br>".$output."<br>".$text."<br>".$executed;} ?> </p>
    85. <p><img name="example" src="/images/mg/test.gif" alt="example">
    86. <a href=/images/mg/test.gif>direct link</a></p>
    87. </body>
    88. </html>
    89.  
    nevetS, Aug 19, 2005 IP
    Nitin M likes this.
  6. J.D.

    J.D. Peon

    Messages:
    1,198
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Here's a little example on how you can overlap two GIF files. The example rotates background color, so you can see how GIF blends in (not very well - there's no levels of transparency). The circles initially were 50%-transparent in the imaging program, but this info is lost when the file is saved as a GIF - this is why you can't see the black square underneath.

    Copy all files in the example to the same directory and click on the HTML file (IE will give you a warning because there's a JS method call in the onload handler - you can either allow it or block it, doesn't matter).

    J.D.
    J.D., Aug 19, 2005 IP
  7. jgcalifornia

    jgcalifornia Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    will this work if one of these has a click able link on it?
    jgcalifornia, Oct 19, 2009 IP