Jump to content


Photo

Image Editing


  • Please log in to reply
8 replies to this topic

#1 baber_abbasi

baber_abbasi
  • Members
  • PipPipPip
  • Advanced Member
  • 33 posts
  • LocationPakistan

Posted 13 April 2006 - 06:06 AM

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.
Baber N Abbasi

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 13 April 2006 - 06:39 AM

[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]
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 baber_abbasi

baber_abbasi
  • Members
  • PipPipPip
  • Advanced Member
  • 33 posts
  • LocationPakistan

Posted 14 April 2006 - 07:01 AM

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.


<?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);
?>

Baber N Abbasi

#4 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 14 April 2006 - 08:10 AM

imagepng($dimage, $fname);

And don't forget to call imagedestroy() on the source and dest images at end of script.
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#5 baber_abbasi

baber_abbasi
  • Members
  • PipPipPip
  • Advanced Member
  • 33 posts
  • LocationPakistan

Posted 16 April 2006 - 04:14 PM

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.
Baber N Abbasi

#6 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 16 April 2006 - 06:15 PM

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.
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#7 baber_abbasi

baber_abbasi
  • Members
  • PipPipPip
  • Advanced Member
  • 33 posts
  • LocationPakistan

Posted 16 April 2006 - 07:05 PM

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.
Baber N Abbasi

#8 redbullmarky

redbullmarky
  • Staff Alumni
  • Advanced Member
  • 2,863 posts
  • LocationBedfordshire, England

Posted 16 April 2006 - 07:21 PM

[!--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) View Post[/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
"you have to keep pissing in the wind to learn how to keep your shoes dry..."

I say old chap, that is rather amusing!

#9 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 16 April 2006 - 07:27 PM

Either

$new_image = imagecreate ($newwidth, $newheight);
or, better for jpegs,
$new_image = imagecreatetruecolor ($newwidth, $newheight);

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
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users