Use PHP to create embossing effect: add white border to bottom edges and black border to other edges, rest of image should be 5% black -


i know if possible use php create embossing effect on user uploaded logo.

the effect (according photoshop department) achieved transforming contents of logo black (so 1 color), , make 'layer' 5% filled (so becomes 95% transparent). after add black border top/left/right edges of logo, , white border bottom edge of logo. , edges, not outside of image itself; edges of content of logo needs traced.

as not known in image processing, wondering if php expert me out/point me in right direction on how this?

so sum up, need 4 things:

  • convert contents of image black (but keep transparency)
  • make image 95% transparent
  • add black border top/left/right edges of contents of image
  • add white border bottom edges of contents of image

if achieved in css browsers ie10 , up, solution well. in advance!

edit

here example of logo created artists, on top of image/background/pattern: http://picpaste.com/embos-example-ngxfsaj5.png - did in bit different way first told me :) in photoshop added inner shadow in black top down, , drop shadow in white bottom top

it seems not asking right questions.. when translating effect dutch (preeg) english, thought in need of embossing effect.. found php function shadeimage wanted. in order other people, i'll post did achieve this.

to use shadeimage, have supply black/white image. went wrong when first trying out function. first made function translate image black/grey/white, based on alpha channel of each pixel. after used shadeimage. resulting image did have background, had removed. tried using things painttransparentimage, did not work in tests, made custom function, looping on each pixel once again. , set pixels alpha channel value of 0.35, make image bit 'softer' , usable on background. here complete function:

    public function createembossedlogo($imagepath, $embossedfilepath) {         // initialize imagick , load image         $imagick = new \imagick(realpath($imagepath));          // make sure using png, can use alpha channel         $imagick->setimageformat('png');          // resize logo, not have process many pixels         $imagick->resizeimage(200, null,\imagick::filter_catrom,1);          // if image not have margin around content,         // shade cut off @ sides,         // add invisible border of 5 pixels, add margin         $imagick->borderimage('rgba(255,0,0,0)',5, 5);          // have convert image black/white image, using alpha channel         // , use alpha channel value r/g/b channel values          // load pixels of image         $imageiterator = $imagick->getpixeliterator();         foreach ($imageiterator $row => $pixels) { /* loop through pixel rows */             foreach ($pixels $column => $pixel) { /* loop through pixels in row (columns) */                 /** @var $pixel \imagickpixel */                 $nor_color = $pixel->getcolor(true); //normalized color                  // alpha channel 0 if invisible , 1 if visibile                 // can value in between 0-1                 // using alpha channel white/grey/black value, create alpha map                 $alpha = $nor_color['a'];                 $rgbvalue = $alpha*255;                 $pixel->setcolor('rgba('.$rgbvalue.','.$rgbvalue.','.$rgbvalue.',1');             }              $imageiterator->synciterator(); /* sync iterator, important on each iteration */         }          // add shading, first parameter makes sure 'to removed' pixels         // same color, can find them in next loop through pixels         // otherwise black, 1 of colors need keep in result         $imagick->shadeimage(true,270,45);          // shadeimage function make pixels grey should transparent         // loop on pixels in image once again remove them         $imageiterator = $imagick->getpixeliterator();         $colorfound = false;         $colorrange = 10;         foreach ($imageiterator $row => $pixels) { /* loop through pixel rows */             foreach ($pixels $column => $pixel) { /* loop through pixels in row (columns) */                 /** @var $pixel \imagickpixel */                 $color = $pixel->getcolor(); //normalized color                 if (!$colorfound) {                     // since added margin around image, can take first pixel                     // of top left corner, , use color make transparent                     // , since image in black/white, need 1 'color' channel                     $colorfound = array();                     $colorfound['r'] = $color['r'];                 }                  // default alpha pixels keep 1                 $alpha = 1;                  // see if color of pixel close of 'color deleted'                 // if so, not totally delete it, change alpha channel accordingly                 $diff = abs($color['r']-$colorfound['r']);                 if ($diff<=$colorrange) {                     // set alpha value pixel, based on difference removed color                     $alpha = $diff / $colorrange;                 }                  // entire opacity of image has brought down, make image bit 'softer'                 $alpha *= 0.35;                  // pixel matches 'to removed' color, set new value alpha 0                 $pixel->setcolor('rgba('.$color['r'].','.$color['g'].','.$color['b'].','.$alpha.')');             }              $imageiterator->synciterator(); /* sync iterator, important on each iteration */         }          // remove excess margins not needed         $imagick->trimimage(0);          // store image         $imagick->writeimage($embossedfilepath);     } 

Comments