Overlaying colour on a JPEG with PHP/GD? -
I have a collection of black and white JPEGs on my server. These images are symbols, where the symbol is black lines on a white background Is a collection of
I am trying to use the GD to replace the black color with any color flying with the other. Currently, I am: Getting as JPEG: $ image = imagecreatefromjpeg ($ ImgURL), converting a hex code (# FF0000, say) PHP through RGB
and then feeding these variables:
Personal function colorize_image ($ image, $ color, $ contrast = 0) {if (! $ Image) {return false; } Imagealphobalending ($ image, true); Imesacelfa ($ image, true); Convert hex color to # rgb values $ r = hexadec ('0x'. $ Color {0}. $ Color {1}); $ G = hexdec ('0x'. $ Color {2}. $ Color {3}); $ B = hexdack ('0x'. $ Color {4}. $ Color {5}); Imagefilter ($ image, IMG_FILTER_COLORIZE, $ r, $ g, $ b); Imagefilter ($ image, IMG_FILTER_CONTRAST, $ contrast); # Gd image object returns $ image; } For some reason, this job does not work at all (this will not overlay a new color).
Does anyone tell me where I am being wrong?
Many thanks.
If color is the only problem, then you can try it:
& lt; Php & gt;// SNIP $ color = preg_replace ('/ ^ # /', '', $ color); // get rid of "#" if it contains $ r = hexadec ("0x {$ color [0]} {$ color [1]}"; $ G = hexdec ("0x {$ color [2]} { $ Color [3]} "); $ $ b = hexdec (" 0x {$ color [4]} {$ color [5]} "); // SNIP
Comments
Post a Comment