PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
It is currently Wed Apr 24, 2019 9:58 pm

All times are UTC - 5 hours

Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Mon Sep 28, 2009 11:58 am 
Forum Newbie

Joined: Mon Sep 28, 2009 11:37 am
Posts: 1
I need to do very specific job, to make very long story short:
I have my own custom palette with about thousands colours, but many times the desired image could have absolutely different colours than my palette and create poor results. Some sort of dithering is required! Pictures are usually small (smaller than 256x256) but I need to get maximum from it.

Now I use something like this (here is just simple example and instead the palette I'm using random generator)

Syntax: [ Download ] [ Hide ]
    for ($i=0;$i<5000;$i++) {

But imagecopy doesn't have any dithering options (perhaps some hidden, available trough some global variables). Only function that I know uses dithering is imagetruecolortopalette, but there I can only chose number of colours in the palette and the functions itself decides witch palette to use. But I need use my palette so badly that It's better for me use non dither function than dither functions using absolutely useless palette. My palette or nothing, just I need get better results with dithering. Perhaps if somebody has implemented colour quantization and dithering in pure PHP. Many of the images are 128x64 pixels big and never bigger than 256x256. So perhaps some slow manual dithering in pure PHP could be possible if somebody done it already. Or if somebody know some workaround for imagetruecolortopalette to use custom palette.

I tried to trick the imagetruecolortopalette in this steeps:

1) Loaded original image A
2) Creating image B with my palette
3) Converting the palette image B to true color
4) Using imagetruecolortopalette on original image A
5) imageColorMatch() on image A to match palette from B

And it shows little bit of dithering, but in absolutely worst way, it's much worse the non dithered. The problem is that even 256 colors are enough for imagetruecolortopalette create almost true-colour looking image (very fine dithering). But when the colours are matching to my palette all the fine colours and shades of the similar colours are blended into 1 colour in mine palette, so still I have this big flat places flood-filled with 1 my colour. But on edges where I put sharpening filters it's disrupting the effect of sharpening and makes even more errors to image than it was before.

If somebody has ideas what I could try (or do), I will be deeply thankful.

Thanks in advance for your inputs.

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 5 hours

Who is online

Users browsing this forum: No registered users and 2 guests

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 post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group