[PHP]How to "join" two images?

Newbie Spellweaver
Joined
Feb 8, 2005
Messages
34
Reaction score
0
Hello i'm making a web-based online game and i wanna know how to join two images by using PHP.

Example:
I have this image
Manguito68 - [PHP]How to "join" two images? - RaGEZONE Forums

And i want that image to be joined with this one:
Manguito68 - [PHP]How to "join" two images? - RaGEZONE Forums

so if you understand it will be like this:
Manguito68 - [PHP]How to "join" two images? - RaGEZONE Forums

well i have made it quickly but i think you'll get what i wanna do.

Also I want to do this with armors, gloves, boots, etc.

If someone wants to help me with my Web-Based-Game project (or something like that) that advise me on e-mail: [email protected] or here or by PM...
 
You use GD, I will post a better explanation later... (if you want check out this)

Alternatively you make the body the background image, and place the object on top with absolute positioning
 
use can use GIF or better yet PNG files...

if ur using Gif ... create a function that will detect a transparency color... then set it as the transparency color.. commonly i use 0 0 0 as a place to put my transparency color.. once that is it .. use a merge image command with GD

commands are:
imagecreatefromgif - to create a gd image from gif
imagecolortransparent - to set transparency
imagecopymerge - to merge the gif to the main image

but if are going to use a PNG file.. much better and easier..
just make 32 bit PNG with alpha transparency... ( u can use Fireworks since it has better PNG support ) u can even create shadows that is semi transparent.

commands to use:
imagecreatefrompng - create from image from png file
imageAlphaBlending - find alpha transparency
imageSaveAlpha - save it
imagecopymerge - same as the gif one.. will merge with current image

remember to also use
imagesx
imagesy
to get the proper width and hieght of ur inserted image.. and will be used when u copymerge the two images.
 
srry but can you be more simple? because i can't understand everithing :(
and i want , if you can how does this commands woks:
imagecreatefrompng - create from image from png file
imageAlphaBlending - find alpha transparency
imageSaveAlpha - save it
imagecopymerge - same as the gif one.. will merge with current image

remember to also use
imagesx
imagesy
????????¿¿¿¿¿¿¿¿¿



IF YOU CAN (PLEASE DO IT) MAKE AN EXAPLE OF HOW CAN I JOIN THE IMAGES IN THE EXAMPLE...
 
Last edited:
PHP:
<?php

$src_file = 'test1.jpg';
list($src_w, $src_h, $src_t, $src_a) = getimagesize($src_file);

$ptr_file = 'test2.png'; // must have no transparency, but white background
list($ptr_w, $ptr_h, $ptr_t, $ptr_a) = getimagesize($ptr_file);

// destination image dimensions:
$dst_w = 48;
$dst_h = 112;

// pointer position:
$ptr_x = 30;
$ptr_y = 55;

$srcImage = imageCreateFromJpeg($src_file) or die ('failed imageCreateFromJpg'); 
$dstImage = imageCreateTrueColor($dst_w, $dst_h) or die ('failed imageCreateTrueColor'); 

imageCopyResampled($dstImage, $srcImage, 0, 0, 0, 0, $dst_w, $dst_h, $src_w, $src_h) or die ('failed imageCopyResampled'); 

Header("Content-type: image/png");

$ptrImage = imageCreateFromPng($ptr_file) or die ('failed imageCreateFromPng'); 

$ptr_white = imageColorAllocate($ptrImage,255,255,255);
imageColorTransparent($ptrImage,$ptr_white);

imageCopyMerge($dstImage, $ptrImage, $ptr_x, $ptr_y, 0, 0, $ptr_w, $ptr_h, 100) or die ('failed imageCopyMerge');

imageJpeg($dstImage,'',100) or die ('failed imageJpeg');

imageDestroy($srcImage) or die ('failed imageDestroy(1)');
imageDestroy($dstImage) or die ('failed imageDestroy(2)');
imageDestroy($ptrImage) or die ('failed imageDestroy(3)');

?>

This would end up like this:

Manguito68 - [PHP]How to "join" two images? - RaGEZONE Forums


test1.jpg is the body image
test2.png is the weapon image with white (255,255,255) bg.
 
on that script by silver.. the PNG image must have a white BG...

but if ur going to use PNG/.. why not use alpha blending .. since has more poweful transparency blending
 
but i can't make the axe gif because it wouldn't work :(:(...
and the background is 255,255,255!!!
i tested it with black (0,0,0) and it worked but it shows like this:
Manguito68 - [PHP]How to "join" two images? - RaGEZONE Forums
 
$insert2 = imagecreatefrompng("mypngfile");
imageAlphaBlending($insert2, true);
imageSaveAlpha($insert2, true);
$insert_x = imagesx($insert2);
$insert_y = imagesy($insert2);
imagecopymerge($input,$insert2,$X,$Y,0,0,$insert_x,$insert_y,100);

wer $input is the main image object
$X,$Y x,y coordinates for the insert.

now make the perfect PNG image.. u need to create a PNG32 file... with a transparent background. or no background
 
use photoshop and magic tool, edit the axe, remove the background and all done
 
WOA!!!
I made it...
1°: i take the png file and make it .TIF.
2°: i opened it with photoshop, then used background eraser.
3°: saved the drawing and make it .PNG in paint.
4°: it worked... here the prove:
Manguito68 - [PHP]How to "join" two images? - RaGEZONE Forums


WEEE THANKS to EveRyOnE who helped...
 
WOA!!!
I made it...
1°: i take the png file and make it .TIF.
2°: i opened it with photoshop, then used background eraser.
3°: saved the drawing and make it .PNG in paint.
4°: it worked... here the prove:
Manguito68 - [PHP]How to "join" two images? - RaGEZONE Forums


WEEE THANKS to EveRyOnE who helped...
well u had to do in the first place was get Fireworks and save as PNG.. like i said before Macromedia Fireworks has better PNG management and creation and silly old Photoshop who hates PNGs
 
Back