You are here: Re: [PHP] White background with imagecreatetruecolor() [SOLVED] « PHP « IT news, forums, messages
Re: [PHP] White background with imagecreatetruecolor() [SOLVED]

Posted by John Nichel on 10/18/05 22:34

John Nichel wrote:
> I'm diving into the gd functions for the first time, and I'm having a
> problem creating a white background for an image when using
> imagecreatetruecolor(). The manual says that this function will create
> a _black_ image, but looking at imagecolorallocate() it says that the
> first call to this function fills the background color, and they have
> examples like this...
>
> $im = imagecreatetruecolor('example.jpg');
> // sets background to red
> $background = imagecolorallocate($im, 255, 0, 0);
>
> So, thinking that I could make a this with a white background, I did
> this...
>
> $im = imagecreatetruecolor ( 140, 140 );
> $bg = imagecolorallocate ( $im, 255, 255, 255 );
> $orgimg = imagecreatefromjpeg ( $image_data['image'] );
>
> imagecopyresampled ( $im, $orgimg, $thumb_x_offset, $thumb_y_offset, 0,
> 0, $new_thumb_x, $new_thumb_y, $image_data['image_x'],
> $image_data['image_y'] );
>
> imagejpeg ( $im, $image_paths['thumbs'] . $file_name );
>
> And that creates the image with the right sizes and positions, but the
> background is black. Is there something wrong in my code, or is the
> manual wrong on the imagecolorallocate() function? TIA.
>

The manual is _my_ friend....at least the comments in the manual are. I
had to use the imagefill() function...

$im = imagecreatetruecolor ( 140, 140 );
$bg = imagecolorallocate ( $im, 255, 255, 255 );
imagefill ( $im, 0, 0, $bg );

--
John C. Nichel
ÜberGeek
KegWorks.com
716.856.9675
john@kegworks.com

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация