Exemplo n.º 1
0
 /**
  * @param  resource $resource
  * @param  resource $controlResource
  * @return resource
  */
 public function getOptimizedGdResource($resource, $controlResource)
 {
     if (imageistruecolor($resource)) {
         $resource = $this->rh->getPalettizedGdResource($resource);
     }
     $totalColors = imagecolorstotal($resource);
     $trans = imagecolortransparent($resource);
     $reds = new \SplFixedArray($totalColors);
     $greens = new \SplFixedArray($totalColors);
     $blues = new \SplFixedArray($totalColors);
     $i = 0;
     do {
         $colors = imagecolorsforindex($resource, $i);
         $reds[$i] = $colors['red'];
         $greens[$i] = $colors['green'];
         $blues[$i] = $colors['blue'];
     } while (++$i < $totalColors);
     if (imageistruecolor($controlResource)) {
         $controlResource = $this->rh->getPalettizedGdResource($controlResource);
     }
     $controlTotalColors = imagecolorstotal($controlResource);
     $controlTrans = imagecolortransparent($controlResource);
     $controlReds = new \SplFixedArray($controlTotalColors);
     $controlGreens = new \SplFixedArray($controlTotalColors);
     $controlBlues = new \SplFixedArray($controlTotalColors);
     $i = 0;
     do {
         $colors = imagecolorsforindex($controlResource, $i);
         $controlReds[$i] = $colors['red'];
         $controlGreens[$i] = $colors['green'];
         $controlBlues[$i] = $colors['blue'];
     } while (++$i < $controlTotalColors);
     $width = imagesx($resource);
     $height = imagesy($resource);
     $y = 0;
     do {
         $x = 0;
         do {
             $index = imagecolorat($resource, $x, $y);
             $red = $reds[$index];
             $green = $greens[$index];
             $blue = $blues[$index];
             $controlIndex = imagecolorat($controlResource, $x, $y);
             $controlRed = $controlReds[$controlIndex];
             $controlGreen = $controlGreens[$controlIndex];
             $controlBlue = $controlBlues[$controlIndex];
             if (($red & 0b11111100) === ($controlRed & 0b11111100) && ($green & 0b11111100) === ($controlGreen & 0b11111100) && ($blue & 0b11111100) === ($controlBlue & 0b11111100)) {
                 imagesetpixel($resource, $x, $y, $trans);
             }
         } while (++$x !== $width);
     } while (++$y !== $height);
     return $resource;
 }
Exemplo n.º 2
0
 /**
  * @param LayerInterface[] $layers
  * @param mixed[]          $options
  */
 protected function initContents(array $layers, $options)
 {
     $format = $layers[0]->get('image.format');
     if ($layers[0]->has('image.imc_uri')) {
         $uri = $layers[0]->get('image.imc_uri');
         $resource = $this->rh->getGdResourceFromStream($format, $uri, true);
         imagedestroy($resource);
         $contents = file_get_contents($uri);
     } else {
         $contents = $layers[0]->get('image.contents');
         $resource = $this->rh->getGdResourceFromContents($format, $contents, true);
         imagedestroy($resource);
     }
     $layers[0]->set('final.contents', $contents);
 }
 /**
  * @param PhpGdEvent
  */
 public function initFinalDimensions(PhpGdEvent $event)
 {
     $layers = $event->getLayers();
     foreach ($layers as $layer) {
         if (!$layer instanceof ImageAwareLayerInterface) {
             continue;
         }
         $width = $layer->get('image.width');
         $height = $layer->get('image.height');
         if ($layer->has('image.resize.width')) {
             $args = $this->rh->getResizeArguments($width, $height, $layer->get('image.resize.width'), $layer->get('image.resize.height'), $layer->get('image.resize.option'));
             if ($args) {
                 $width = $args['dst_w'];
                 $height = $args['dst_h'];
             }
         }
         $layer->add(['final.width' => $width, 'final.height' => $height]);
     }
 }
Exemplo n.º 4
0
 /**
  * @param  string $contents
  * @return resource
  */
 protected function getGifResourceFromContents($contents)
 {
     return $this->rh->getGdResourceFromContents(PhpGdContext::FORMAT_GIF, $contents, true);
 }
Exemplo n.º 5
0
 /**
  * @param TextLayerInterface $layer
  */
 protected function initTextLayerResource(TextLayerInterface $layer)
 {
     $resource = $this->rh->getTextGdResource($layer->get('text.font.filename'), $layer->get('text.font.size'), $layer->get('text.font.rgb_color'), $layer->get('text.label'), $layer->get('text.line_spacing'), $layer->get('text.angle'), $layer->get('text.box.paddings'), $layer->get('text.box.rgb_color'));
     $layer->set('final.resource', $resource);
 }