bit-tech.net

Go Back   bit-tech.net Forums > Technology > Software

Reply
 
Thread Tools
Old 24th Jul 2006, 06:07   #1
CaseyBlackburn
Network Techie
 
CaseyBlackburn's Avatar
 
Join Date: Jul 2004
Location: Mckinney,Tx,US Geek:75.7%
Posts: 1,846
CaseyBlackburn has yet to learn the way of the Dremel
PHP: Combine Multiple Image with GD?

Alright guys, I am in a little bit of a bind. I need to combine 5 images into one, but I can't just make them together, because one of them is dynamic, but in the end they need to be one image. I decided that the GD Library is what I need for this, but I don't know how to call multiple images into the script for it.

Here is my current code, which currently only loads 1 of the 5 images, and it is the one that needs to be dynamic:
PHP Code:
<?php

header
("Content-type: image/png");
$im=imagecreatefrompng("http://miniprofile.xfire.com/bg/bg/type/1/blackburnperson.png");
imagepng($im);
imagedestroy($im);
?>
I want the end result to be one image that looks like this:
TOP TOP TOP TOP TOP TOP TOP TOP
LEFT CENTER CENTER RIGHT RIGHT
BOTTOM BOTTOM BOTTOM BOTTOM


In other words, very much like: This
__________________
Casey Blackburn
My art - CaseyBlackburn @ dA
Get Firefox - Take Back The Web

Last edited by CaseyBlackburn; 24th Jul 2006 at 06:17.
CaseyBlackburn is offline   Reply With Quote
Old 24th Jul 2006, 09:47   #2
ST8
Supermodder
 
ST8's Avatar
 
Join Date: Feb 2003
Location: :|/\/\
Posts: 596
ST8 has yet to learn the way of the Dremel
Look at the imagecopy function for merging multiple images, i use it to dynamically add copyright to my images when hotlinked
__________________

DeviantART
Bleh
ST8 is offline   Reply With Quote
Old 24th Jul 2006, 12:00   #3
Bogomip
... Yo Momma
 
Bogomip's Avatar
 
Join Date: Jun 2002
Location: Cambridge, Edinburgh
Posts: 5,135
Bogomip - it's over 9000!!!!!!!!1!1!1!!!Bogomip - it's over 9000!!!!!!!!1!1!1!!!Bogomip - it's over 9000!!!!!!!!1!1!1!!!Bogomip - it's over 9000!!!!!!!!1!1!1!!!Bogomip - it's over 9000!!!!!!!!1!1!1!!!Bogomip - it's over 9000!!!!!!!!1!1!1!!!Bogomip - it's over 9000!!!!!!!!1!1!1!!!Bogomip - it's over 9000!!!!!!!!1!1!1!!!Bogomip - it's over 9000!!!!!!!!1!1!1!!!Bogomip - it's over 9000!!!!!!!!1!1!1!!!Bogomip - it's over 9000!!!!!!!!1!1!1!!!
Yeah, the imagecopy function is what you need, though I had some difficulty using only that - for some reason. The imagecopyresampled function seemed to work better - also try looking at imagecopymerge.

I used them functions to create http://www.sweeto.org/site/vs.php - the code looks fairly simple, though took me a while from what i remember

edit: thats 3 images merged into one by the way - 2 pictures have their transparency altered and two are .png's and one is a gif iirc.
Bogomip is offline   Reply With Quote
Old 24th Jul 2006, 14:57   #4
CaseyBlackburn
Network Techie
 
CaseyBlackburn's Avatar
 
Join Date: Jul 2004
Location: Mckinney,Tx,US Geek:75.7%
Posts: 1,846
CaseyBlackburn has yet to learn the way of the Dremel
Mind posting your code Bogomip so I can get an idea of how it is done?

EDIT:I have offically gotten it to work, below is my code
PHP Code:
<?
header ("Content-type: image/png");
$src = array ("http://img164.imageshack.us/img164/5175/toprb3.jpg","http://img123.imageshack.us/img123/9056/leftij4.jpg","http://miniprofile.xfire.com/bg/bg/type/1/blackburnperson.png", "http://img67.imageshack.us/img67/4786/rightnt1.jpg","http://img123.imageshack.us/img123/4891/bottomtp5.jpg");   
$imgBuf = array ();
foreach ($src as $link)
{
   switch(substr ($link,strrpos ($link,".")+1))
   {
       case 'png':
           $iTmp = imagecreatefrompng($link);
           break;
       case 'gif':
           $iTmp = imagecreatefromgif($link);
           break;               
       case 'jpeg':           
       case 'jpg':
           $iTmp = imagecreatefromjpeg($link);
           break;               
   }
   array_push ($imgBuf,$iTmp);
}
$iOut = imagecreatetruecolor ("450","131") ;
imagecopy ($iOut,$imgBuf[0],0,0,0,0,imagesx($imgBuf[0]),imagesy($imgBuf[0]));
imagedestroy ($imgBuf[0]);
imagecopy ($iOut,$imgBuf[1],0,54,0,0,imagesx($imgBuf[1]),imagesy($imgBuf[1]));
imagedestroy ($imgBuf[1]);
imagecopy ($iOut,$imgBuf[2],15,54,0,0,imagesx($imgBuf[2]),imagesy($imgBuf[2]));
imagedestroy ($imgBuf[2]);
imagecopy ($iOut,$imgBuf[3],292,54,0,0,imagesx($imgBuf[3]),imagesy($imgBuf[3]));
imagedestroy ($imgBuf[3]);
imagecopy ($iOut,$imgBuf[4],0,117,0,0,imagesx($imgBuf[4]),imagesy($imgBuf[4]));
imagedestroy ($imgBuf[4]);
imagepng($iOut);
?>
__________________
Casey Blackburn
My art - CaseyBlackburn @ dA
Get Firefox - Take Back The Web

Last edited by CaseyBlackburn; 24th Jul 2006 at 15:45.
CaseyBlackburn is offline   Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:56.
Powered by: vBulletin Version 3
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.