baber_abbasi Posted April 13, 2006 Share Posted April 13, 2006 Hi,I need to edit an image so as I can insert another small image in it at some given location/coordinates.For example;mainImage = abc.gifinsertImage = xyz.gifI need to insert xyz.gif into abc.gif at some given location/coordinates.Pls tell me how its possible. Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/7282-image-editing/ Share on other sites More sharing options...
Barand Posted April 13, 2006 Share Posted April 13, 2006 [a href=\"http://www.php.net/imagecopy\" target=\"_blank\"]http://www.php.net/imagecopy[/a][a href=\"http://www.php.net/imagecopymerge\" target=\"_blank\"]http://www.php.net/imagecopymerge[/a][a href=\"http://www.php.net/imagecopymergegray\" target=\"_blank\"]http://www.php.net/imagecopymergegray[/a][a href=\"http://www.php.net/imagecopyresampled\" target=\"_blank\"]http://www.php.net/imagecopyresampled[/a] Quote Link to comment https://forums.phpfreaks.com/topic/7282-image-editing/#findComment-26486 Share on other sites More sharing options...
baber_abbasi Posted April 14, 2006 Author Share Posted April 14, 2006 Hi Barand,Thanks for the help. imagecopymerge() solved the requirement. Now I need to save the merged image at my server, how can I do this???I am using following code to do this but its not saving updated image in the new image file.Bundle of thanks.[code]<?php//copymergeheader('Content-type: image/png');$simg = "images/abc.jpg"; $simage = imagecreatefromjpeg($simg); $dimg = "xyz.png"; $dimage = imagecreatefrompng($dimg); $dx = 50;$dy = 50;$sx = 50;$sy = 50;$sw = 50;$sh = 50;$pct = 100;imagecopymerge($dimage, $simage, $dx, $dy, $sx, $sy, $sw, $sh, $pct);imagepng($dimage);// save the file $fname = $dimg;if(!($fq= fopen ($fname, "w+"))) die ("Can't open");fwrite ($fq, imagepng($dimage));fclose ($fq);?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/7282-image-editing/#findComment-26895 Share on other sites More sharing options...
Barand Posted April 14, 2006 Share Posted April 14, 2006 [code]imagepng($dimage, $fname);[/code]And don't forget to call imagedestroy() on the source and dest images at end of script. Quote Link to comment https://forums.phpfreaks.com/topic/7282-image-editing/#findComment-26899 Share on other sites More sharing options...
baber_abbasi Posted April 16, 2006 Author Share Posted April 16, 2006 Hi Barand,Thanks a ton, it worked great for me. I am now stuck in another situation and hope you can help me find a way out of it. :)I have following x.y (co-ordinates) and I need to resize an image based on these co-ordinates. 50,060,050,1060,1050,2060,20These x.y (co-ordinates) make a shape of 'vertical rectangle' like below but image file is in square shape.--| || |--This is something, I am looking to edit my image file-(in square shape) to have a new shape based on above x.y (co-ordinates).Thanks in advance and I will appreciate anyone giving useful hints/codes. Quote Link to comment https://forums.phpfreaks.com/topic/7282-image-editing/#findComment-27489 Share on other sites More sharing options...
Barand Posted April 16, 2006 Share Posted April 16, 2006 The relevant coordinates from that list are top-left (50, 0) and bottom-right (60, 20) defining a rectangle of width 10 and height 20.The imagecopy() function will take all or part of your existing image and place it in that rectangle.It's up to whether you want to take a 10x20 section of the original or a different sized section and distort the image to fit. Quote Link to comment https://forums.phpfreaks.com/topic/7282-image-editing/#findComment-27512 Share on other sites More sharing options...
baber_abbasi Posted April 16, 2006 Author Share Posted April 16, 2006 Thanks.Can you tell me how an image size can be changed?? Like I have an image and I need to change its width/height, which function can do this?? and change without breaking its pixels.Thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/7282-image-editing/#findComment-27526 Share on other sites More sharing options...
redbullmarky Posted April 16, 2006 Share Posted April 16, 2006 [!--quoteo(post=365362:date=Apr 16 2006, 08:05 PM:name=baber_abbasi)--][div class=\'quotetop\']QUOTE(baber_abbasi @ Apr 16 2006, 08:05 PM) [snapback]365362[/snapback][/div][div class=\'quotemain\'][!--quotec--]Thanks.Can you tell me how an image size can be changed?? Like I have an image and I need to change its width/height, which function can do this?? and change without breaking its pixels.Thanks again.[/quote]imagecopyresized is the quickest way, imagecopyresampled is the neatest way.[a href=\"http://www.php.net/imagecopyresized\" target=\"_blank\"]http://www.php.net/imagecopyresized[/a][a href=\"http://www.php.net/imagecopyresampled\" target=\"_blank\"]http://www.php.net/imagecopyresampled[/a]both functions take exactly the same parameters. only final difference is the quality.you'd be good to have a good look through the user notes and other functions whilst you're there as you'll be able to pick up quite alot in one go.hope it helpscheersMark Quote Link to comment https://forums.phpfreaks.com/topic/7282-image-editing/#findComment-27536 Share on other sites More sharing options...
Barand Posted April 16, 2006 Share Posted April 16, 2006 Either[code]$new_image = imagecreate ($newwidth, $newheight);[/code]or, better for jpegs,[code]$new_image = imagecreatetruecolor ($newwidth, $newheight);[/code]then use imagecopy() as in my last post to copy all (will distort) or part, to crop the old image.You will get distortion if the portion of the original image does not match the size of the new.EDIT: yes, as redbull said Quote Link to comment https://forums.phpfreaks.com/topic/7282-image-editing/#findComment-27539 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.