php - fabric js or imagick remove white from image -


i got situation hard me search on google , explain.

our company prints photos on aluminium , give our customers 2 choices.

  1. the first choice print pictures on aluminium gave picture us, if picture has white background picture gets printed white background. easy that.

  2. the second option can print picture without using white. instead of "white values" (<- best can come explain) being printed leave transparent.

i know there removewhite filter in fabric js can replace white areas transparent ones. not need. need fabric js filter, imagemagick thing or other php or js solution can turn "white value" of pixel transparent. know stuff may sounds vague guys, let me try explain way:

  • if come across white pixel need make transparent.

  • if come across grey pixel, need turn combination of white , black combination of transparent , black.

  • if come cross coloured pixel, need turn "white value" makes light turn transparent.

here before , after example of filter/effect try accomplish:

before:

after:

please don't hesitate ask me if don't understand i'm asking for.

i got work. using factors yuv color space, create fabric js image filter.

it lot of trial-and-error result looking for. therefore don't have (detailed) description of how works. know have used yuv factors brightness of (rgb) colours.

for (i = 0; < ilen; i++) {     (j = 0; j < jlen; j++) {       index = (i * 4) * jlen + (j * 4);       var yuv = {};       yuv.r = data[index] / 255 * 1 * 0.299;            yuv.g = data[index + 1] / 255 * 1 * 0.587; //we use yuv formula constants       yuv.b = data[index + 2] / 255 * 1 * 0.114; //to try catch y (brightness)       yuv.y = yuv.r + yuv.g + yuv.b;             //you can tweak       data[index + 3] = 350 - (yuv.y / 1 * 255); //by changing first number after "=" on line!     } } 

somehow messing 350 on last line can alter transparency factor.

sorry not being able explain more how fabric filter works.


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

Cross-Compiling Linux Kernel for Raspberry Pi - ${CCPREFIX}gcc -v does not work -

java.lang.NoClassDefFoundError When Creating New Android Project -