I want to write a routine which takes PNG image path as parameter and convert that image into 8-bit PNG image. I need to use PHP GD library for this.
How to convert PNG to 8-bit PNG using PHP GD library
10.2k Views Asked by Nilesh At
2
There are 2 best solutions below
0
Kornel
On
Instead of GD library I strongly recommend using pngquant 1.5+ commandline using exec() or popen() functions.
GD library has very poor-quality palette generation code.
Same image as in the other answer, same file size as GD library, but converted using pngquant to merely 100 colors (not even 256):

pngquant supports alpha transparency very well.
Related Questions in PHP
- php Variable name must change in for loop
- register_shutdown_function is not getting called
- Query returning zero rows despite entries existing
- Retrieving *number* pages by page id
- Automatically closing tags in form input?
- How to resize images with PHP PARSE SDK
- how to send email from localhost using codeigniter?
- Mariadb max Error while sending QUERY packet PID
- Multiusers login redirect different page in php
- Imaginary folder when I use "DirectoryIterator" in PHP?
- CodeIgniter + XDebug: debug only working in the main controller, index() function
- PHP script timeout when I use sleep()
- posting javascript populated form to another php page
- AJAX PHP - Reload div after submit
- PHP : How can I check Array in array?
Related Questions in PNG
- Understanding the function of this particular 9 patch image
- How can I convert PNG to GIF keeping the transparency?
- Conversion from MathML equation to flash?
- Overlay image in ts file
- gnuplot png white on black
- Using R to convert png files to animation
- PNG transparent backgrounds appearing black when using Android Studio
- Post png image to pngcrush with Ruby
- Skip bytes in ByteArray Java
- Random Line Appearing on Moving Texture Node
- How do I grep GZ files to extract PNG files?
- png uncompressed by CGContextDrawImage is different from orign png image in xcode
- Why the first byte of .png file is 0x89?
- worklight server preview wont show png resources anymore after configuring it to serve svg
- Android: Embedding a compressed image inside a PDF document
Related Questions in GDLIB
- PHP gdlib or imagemagick lighting normalization between 2 images
- PHP GD Library, how to paste text after another text block
- How to give border to text in PHP GD library
- Save image after copying it with PHP's GD Library
- PHP ImageTTFText
- PHP GD Library cannot Merge to image using function
- Convert background on RGB jpg to be transparent
- Embedding transparent png onto an image is too slow
- PHP - save a converted image into a folder
- Uploading Image(manipulated) using Javascript to facebook
- Is it possible to create an PNG with full alpha channel by using: imagecolortransparent()
- Image curving with PHP or HTML5
- How would I skew an image with GD Library?
- PHP image creation from hex values in database
- Codeigniter and uploading zip files
Related Questions in PNG-8
- Create and write paletted RGBA PNG using NSImage
- writing 8-bit png with a transparent color from C++ in Windows
- PHP GD only: PNG24+Alpha => PNG8 does not save Alpha
- PHP gdLib 8-Bit PNG with alpha
- Use png8 instead of png24 as RGB height map
- How to convert PNG to 8-bit PNG using PHP GD library
- Imagemagick lower PNG depth
- Is there some library in Java to compress Png images like pngout?
- What is difference between png8 and png24
- How to tell if image is PNG24 or PNG8 and the number of bits and channels?
- How to remove the alpha channel of a png-24 image by java?
- Create Paletted CGImageRef
- How to save 8-bit PNGs with ChunkyPNG or RMagick
- Convert 32 bit png to 8 bit png with ImageMagick by preserving semi transparent pixels
- Save PNG as PNG-8 with Floyd-Steinberg 2 dithering like GIMP in PHP
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
To convert any PNG image to 8-bit PNG use this function, I've just created
function convertPNGto8bitPNG ()
Parameters
Note
I recommend to make sure that
$sourcePathexists and$destPathis writable before running this code. Maybe this function won't work with some transparent images.Usage
Example (original -> 8-bit)
(Source: pfc.png) ORIGINAL PNG IMAGE
(Destination: pfc8bit.png) CONVERTED PNG IMAGE (8-bit)
Hope someone finds this helpful.