andy's php projects
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
Script and site usage:
All of the scripts on this site are provided free for non-commerical, personal or non-profit use. If you find these scripts useful to you, appreciate the free support, or are just an all round nice person, then why not donate a little dosh? If you wish to use any of these in a commercial system, please refer to the payment plan.


Converting 8 bit png generates 24 bit png -> too big!

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    php.amnuts.com Forum Index -> Drop Shadowed Thumbnail Creator
View previous topic :: View next topic  
Author Message
Jones
Newbie


Joined: 24 Feb 2005
Posts: 3

PostPosted: Thu Feb 24, 2005 8:29 pm    Post subject: Converting 8 bit png generates 24 bit png -> too big! Reply with quote

Hi,

I am trying to convert 8 bit or 256 bit PNG pics with your tool, but I always get 24 bit PNGs out, no matter what I try!

How can I get PNGs with the same colorrange? 24 bit pix are much too big....

Thanks you!

Jones
Back to top
View user's profile Send private message
amnuts
Site Admin


Joined: 01 Sep 2002
Posts: 662
Location: East Sussex, England

PostPosted: Fri Feb 25, 2005 4:02 am    Post subject: Reply with quote

Hi Jones, welcome to the board!

Haven't tried this myself, but... I suspect that the reason you're getting it saved as a 24-bit image is because when the image gets loaded, resized (and, if you choose to, has shadows applied) it's done with imagecreatetruecolor(). This will create a 24-bit image. What you need to do, just before the save, is convert that to a paletted image, an 8-bit version of what you had. This can be done with the imagetruecolortopalette() function in PHP.

http://www.php.net/imagetruecolortopalette

You could either update the drop shadow class, or extend that with your own class which simply re-writes the save function. (That way if a new version is released by me that you want to use, you don't have to apply your changes to my code again.)

Regards,

Andy
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Jones
Newbie


Joined: 24 Feb 2005
Posts: 3

PostPosted: Sun Feb 27, 2005 3:25 pm    Post subject: imgShadow Reply with quote

Hi,

thank you very much for your reply!

OK, I added a trigger class variable that calls

if ($this->reduce_to_256) { imagetruecolortopalette ( $img, false, 256); }
in function _saveImage, what seems to work quite good.

BTW, why doesn?t the shadow function work with ImageCreate?

It just outputs the shadows as black borders. Not really important, just wanted to learn something about "how it works". Anyway, THANK YOU!

Jones
Back to top
View user's profile Send private message
amnuts
Site Admin


Joined: 01 Sep 2002
Posts: 662
Location: East Sussex, England

PostPosted: Mon Feb 28, 2005 6:13 am    Post subject: Reply with quote

At a guess, I'd save that black-block effect you're getting is to do with the shadow png files being saved as 24-bit pngs using full alpha channel capabilities, and the code used in imagetruecoloetopalette. From the PHP site itself:

Quote:
imagetruecolortopalette() converts a truecolor image to a palette image. The code for this function was originally drawn from the Independent JPEG Group library code, which is excellent. The code has been modified to preserve as much alpha channel information as possible in the resulting palette, in addition to preserving colors as well as possible. This does not work as well as might be hoped. It is usually best to simply produce a truecolor output image instead, which guarantees the highest output quality.


Not quite sure what to suggest as a work around, sorry!

Andy
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
amnuts
Site Admin


Joined: 01 Sep 2002
Posts: 662
Location: East Sussex, England

PostPosted: Mon Feb 28, 2005 6:17 am    Post subject: Reply with quote

I just read your thread again and it asks why the pngs don't work with imagecreate, rather than when converting from true colour to palette (which is how I answered it). The answer goes back to the png-24 images used for the shadows. The 8-bit imagecreate function just can't deal with that level of alpha channel, so just black-blocks it. If you need the resultant file to be 8-bit, but do have GD 2.0.1+, then create as a true colour image and just covert down as you're doing.

Andy
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Jones
Newbie


Joined: 24 Feb 2005
Posts: 3

PostPosted: Mon Feb 28, 2005 8:57 am    Post subject: thanks again Reply with quote

ok, thanks again.

BTW beautiful girl on the picture with you, congratulations, you must be a lucky man!

have a nice day,
Jones
Back to top
View user's profile Send private message
amnuts
Site Admin


Joined: 01 Sep 2002
Posts: 662
Location: East Sussex, England

PostPosted: Mon Feb 28, 2005 9:51 am    Post subject: Re: thanks again Reply with quote

Jones wrote:
BTW beautiful girl on the picture with you, congratulations, you must be a lucky man!


Thanks, Jones! She's my wife, and, yeah, I do feel very lucky! Smile

Have a great one!!

Andy
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    php.amnuts.com Forum Index -> Drop Shadowed Thumbnail Creator All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group