0

I want to add a new feature in my present image upload script and that is automatic compression of images just like TinyPng.Basically i want a code snippet that detect 24bit PNG file and convert it to 8bit png file with full support for transparency and that also strip any metadata present

Any php based solution would do ,all i found till now use command line and i don't know how to implement these in php.
I need a solution in php please

Thanks for the guidance

2
Contributors
5
Replies
8
Views
4 Years
Discussion Span
Last Post by diafol
0

@diafol thanks for the referance but how do detect if an image is 24bit or 8bit.
Also from googling i found that php gd quality isn't that good and thread didn't say anything about metadata
Also i don't want to convert png to jpg

0

I thought the thread actually created 8bit pngs not jpg.

Try this for info:

$array = get_png_imageinfo($filename);
print_r($array);

Also from googling i found that php gd quality isn't that good and thread didn't say anything about metadata

I thought I'd leave you something to do for yourself. :)

0

Thanks for the tip diafol
Really dude i must admit that i am well verse with image properties and a rookie when it comes to image conversion.
Its a project that i am passionate about and makes me learn new stuff

True Color Image

Array
 (
     [width] => 400
     [height] => 100
     [bit-depth] => 8
     [color] => 6
     [compression] => 0
     [filter] => 0
     [interface] => 0
     [color-type] => Truecolour with alpha
     [channels] => 4
     [bits] => 8
 )

Image Compressed by TinyPNG

 Array
 (
     [width] => 400
     [height] => 100
     [bit-depth] => 8
     [color] => 3
     [compression] => 0
     [filter] => 0
     [interface] => 0
     [color-type] => Indexed-colour
     [channels] => 1
     [bits] => 8
 )

Using the formula
[channels] * [bits] , the image has been converted from 24bit to 8 bit
I used this site to learn more about transparency.
How can this be achieve in php ?
which element in array represent transparency?
How color-type can be converted to index color?

Wow all this questions are poping in my head now.
Anyone can provide a short and yet understand explaination with code sample if possible...

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.