flash gordon Posted March 29, 2006 Share Posted March 29, 2006 Can anyone show me a tutorial or some code that opens two images and then makes them overlap at specific x & y values? I have read the php freaks tutorials on GD, but it doesn't get very indepth at all :(Any help would be much appreciated. Cheers!_me Quote Link to comment https://forums.phpfreaks.com/topic/6073-gd-library-help/ Share on other sites More sharing options...
redbullmarky Posted March 29, 2006 Share Posted March 29, 2006 ok, without writing the code completely:1, create an image large enough for both images (imagecreate)2, open picture your first picture (imagecreatefromjpeg/gif, etc)3, place picture on canvass created in step 1 (imagecopy/imagecopyresized, etc)4, repeat steps 2 and 3 for second picture, or however many pictures you want5, send the headers: header("Content-type: image/jpeg");6, out the image created in step 1 (imagejpeg)ok sod it, here's an example:[code]$canvass = imagecreate(800, 600);$im1 = imagecreatefromjpeg('mypic_one.jpg');imagecopy($canvass, $im1, 20,30,0,0,100,100);$im2 = imagecreatefromjpeg('mypic_two.jpg');imagecopy($canvass, $im2, 200,300,0,0,120,70);imagedestroy($im1);imagedestroy($im2);header("Content-type: image/jpeg");imagejpeg($canvass);[/code] Quote Link to comment https://forums.phpfreaks.com/topic/6073-gd-library-help/#findComment-21866 Share on other sites More sharing options...
flash gordon Posted March 29, 2006 Author Share Posted March 29, 2006 thanks for the help. it has gotten me started some, but I'm having a little trouble. Here is my current code:[code]<?php$size1 = getimagesize('wolverine.jpg');$canvas = imagecreate(($size1[0] + 20), ($size1[1]+20));$im1 = imagecreatefromjpeg('wolverine.jpg');imagecopy( $canvas, $im1, 0, 0, 0, 0, $size1[0], $size1[1] );$size2 = getimagesize('box.jpg');$im2 = imagecreatefromjpeg('box.jpg');imagecopy($canvas, $im2, 200, 300, 0, 0, $size2[0], $size2[1] );header("Content-type: image/gif");imagegif($canvas);imagedestroy($im1);imagedestroy($im2);?>[/code]And here is the output: gone and here is the source image: goneMy questions are: [ol type=\'1\'][*]Why is the canvas showing up gray when I didn't allocate any color vaules to it? [*]Why is the image of wolverine appear to have an alpha set of around 60-70? He looks grey-ed out.[*]How do I control the "Z" or depth index? It is simply a matter of the order of calling imagecopy()?[/ol]Thanks for your time and help thus far!Cheers! Quote Link to comment https://forums.phpfreaks.com/topic/6073-gd-library-help/#findComment-22070 Share on other sites More sharing options...
redbullmarky Posted March 29, 2006 Share Posted March 29, 2006 1, because something is wrong with box.jpg (either its format/loading, etc), or box.jpg is a grey box. try loading it seperately just with:[code]$im = imagecreatefromjpeg('/full/path/to/box.jpg');header("Content-type: image/jpeg");imagejpeg($im);[/code]2, no idea. possibly you may consider using imagecreatetruecolor instead of imagecreate, as they look like quite hi-res pictures.3, everything done overwrites a previous action, just like a painters canvass. so yep - whatever you want on top should be the last thing you actually copy/write.4, even tho you didn't have a 4th question - nice pictures.hope that helpsCheersMark Quote Link to comment https://forums.phpfreaks.com/topic/6073-gd-library-help/#findComment-22114 Share on other sites More sharing options...
Barand Posted March 29, 2006 Share Posted March 29, 2006 You seem to have a surplus image. Try without the canvas and output as jpg<?php$im1 = imagecreatefromjpeg('wolverine.jpg');$size2 = getimagesize('box.jpg');$im2 = imagecreatefromjpeg('box.jpg');imagecopy($im1, $im2, 200, 300, 0, 0, $size2[0], $size2[1] );header("Content-type: image/jpg");imagejpeg($im1);imagedestroy($im1);imagedestroy($im2);?> Quote Link to comment https://forums.phpfreaks.com/topic/6073-gd-library-help/#findComment-22122 Share on other sites More sharing options...
flash gordon Posted March 30, 2006 Author Share Posted March 30, 2006 [!--quoteo(post=359839:date=Mar 29 2006, 05:48 PM:name=Barand)--][div class=\'quotetop\']QUOTE(Barand @ Mar 29 2006, 05:48 PM) [snapback]359839[/snapback][/div][div class=\'quotemain\'][!--quotec--]You seem to have a surplus image. Try without the canvas and output as jpg[/quote]Yes! That looks much better. However, do you have a link or can describe by what you mean of: [b]"You seem to have a surplus image"[/b]?Also, before I read you post I made this little application: [a href=\"http://www.modernmusicians.com/help/test.swf\" target=\"_blank\"]HERE[/a]. Whenver you click on "generate image" the image qualitly isn't very good. Do you (anyone) have any idea why that is? The code I am using for that is as follows: [code]<?php$canvas = imagecreatetruecolor( 300, 350 );$size1 = getimagesize('red.jpg');$im1 = imagecreatefromjpeg('red.jpg');imagecopy( $canvas, $im1, $_POST['rX'], $_POST['rY'], 0, 0, $size1[0], $size1[1] );$size2 = getimagesize('blue.jpg');$im2 = imagecreatefromjpeg('blue.jpg');imagecopy($canvas, $im2, $_POST['bX'], $_POST['bY'], 0, 0, $size2[0], $size2[1] );header("Content-type: image/jpeg");imagejpeg($canvas);imagedestroy($im1);imagedestroy($im2);imagedestroy($canvas);?>[/code]Thanks for all the help guys! Quote Link to comment https://forums.phpfreaks.com/topic/6073-gd-library-help/#findComment-22200 Share on other sites More sharing options...
flash gordon Posted March 31, 2006 Author Share Posted March 31, 2006 anyone know why it is blurry? Quote Link to comment https://forums.phpfreaks.com/topic/6073-gd-library-help/#findComment-22519 Share on other sites More sharing options...
flash gordon Posted April 2, 2006 Author Share Posted April 2, 2006 last bump. Quote Link to comment https://forums.phpfreaks.com/topic/6073-gd-library-help/#findComment-23246 Share on other sites More sharing options...
redbullmarky Posted April 2, 2006 Share Posted April 2, 2006 [!--quoteo(post=360985:date=Apr 2 2006, 10:47 PM:name=flash gordon)--][div class=\'quotetop\']QUOTE(flash gordon @ Apr 2 2006, 10:47 PM) [snapback]360985[/snapback][/div][div class=\'quotemain\'][!--quotec--]last bump.[/quote]i think the quality output from 'imagejpeg' defaults to 75, although it shouldn't really mess things up that much.try[code]imagejpeg($canvas, "", 100);[/code] Quote Link to comment https://forums.phpfreaks.com/topic/6073-gd-library-help/#findComment-23252 Share on other sites More sharing options...
flash gordon Posted April 3, 2006 Author Share Posted April 3, 2006 [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]quality is optional, and ranges from 0 (worst quality, smaller file) to 100 (best quality, biggest file). The default is the default IJG quality value [b](about 75)[/b].[/quote]thanks bully! Quote Link to comment https://forums.phpfreaks.com/topic/6073-gd-library-help/#findComment-23337 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.