Image editing Functions

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ozmodiar
Forum Commoner
Posts: 35
Joined: Sat Jun 01, 2002 6:29 am
Location: Dublin, Ireland

Image editing Functions

Post by ozmodiar »

I have just started using the image editing functions in PHP. I installed the gd extension and it appears to be working(It displays an image). I am trying to write a script to place a an image of a pin on an image of a map.
I got this example from a book put it doesn't seem to work.

Code: Select all

<?php

Header("Content-type: image/jpeg");

$image = ImageCreateFromJPEG("map.jpg");
$icon = ImageCreateFromJPEG("pin.jpg");

$trans = ImageColorAt($icon, 0, 0);
ImageColorTransparant($icon, $trans);

$width = ImageSX($icon);
$height = ImageSY($ican);

ImageCopyResized($image, $icon, 20, 20, 0, 0, $width, $height, $width, $height);
ImageJPEG($image);

ImageDestroy($image);


?>
Can anyone tell me what is wrong with this script or suggest a way of doing it.

Thanks
Ozmodiar
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

This could be a typo from when you posted in the forum but,

Code: Select all

ImageColorTransparant
should be

Code: Select all

ImageColorTransparent
Mac
ozmodiar
Forum Commoner
Posts: 35
Joined: Sat Jun 01, 2002 6:29 am
Location: Dublin, Ireland

Post by ozmodiar »

I changed

Code: Select all

<?php
ImageColorTransparant
?>
to

Code: Select all

<?php
ImageColorTransparent

?>
But it is still not working. The image of the map is appearing but the pin is not appearing on top of it. It appears to be a problem with this line.

Code: Select all

<?php
ImageCopyResized($image, $icon, 20, 20, 0, 0, $width, $height, $width, $height); 

?>
Thanks
Ozmodiar
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

you don't need the resize-version, try

Code: Select all

imagecolortransparent($icon, imagecolorat($icon, 0, 0)); 
imagecopy($image, $icon, 20, 20, 0, 0, imagesx($icon), imagesy($icon));

Code: Select all

$height = ImageSY($ican); // <- typo
ozmodiar
Forum Commoner
Posts: 35
Joined: Sat Jun 01, 2002 6:29 am
Location: Dublin, Ireland

Post by ozmodiar »

Thanks,

Didn't spot that typo.

Its almost working. The colours seem to be a bit messed up.

Here is the address:

http://www.iptrack.cjb.net/image.php

The pin is meant to be black but it is coming up a strange colour.

Thanks,

Ozmodiar
Post Reply