Jump to content

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.
Link to comment
https://forums.phpfreaks.com/topic/7282-image-editing/
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]
Link to comment
https://forums.phpfreaks.com/topic/7282-image-editing/#findComment-26486
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]
Link to comment
https://forums.phpfreaks.com/topic/7282-image-editing/#findComment-26895
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.
Link to comment
https://forums.phpfreaks.com/topic/7282-image-editing/#findComment-27489
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.
Link to comment
https://forums.phpfreaks.com/topic/7282-image-editing/#findComment-27512
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
Link to comment
https://forums.phpfreaks.com/topic/7282-image-editing/#findComment-27536
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
Link to comment
https://forums.phpfreaks.com/topic/7282-image-editing/#findComment-27539
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.