Jump to content

Archived

This topic is now archived and is closed to further replies.

baber_abbasi

Image Editing

Recommended Posts

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.gif
insertImage = xyz.gif

I need to insert xyz.gif into abc.gif at some given location/coordinates.

Pls tell me how its possible.

Thanks in advance.

Share this post


Link to post
Share on other sites
[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]

Share this post


Link to post
Share on other sites
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
//copymerge
header('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]

Share this post


Link to post
Share on other sites
[code]imagepng($dimage, $fname);[/code]

And don't forget to call imagedestroy() on the source and dest images at end of script.

Share this post


Link to post
Share on other sites
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,0
60,0
50,10
60,10
50,20
60,20

These 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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
[!--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 helps
cheers
Mark

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.