当前位置: 首页>>代码示例>>PHP>>正文


PHP Image::setCore方法代码示例

本文整理汇总了PHP中Intervention\Image\Image::setCore方法的典型用法代码示例。如果您正苦于以下问题:PHP Image::setCore方法的具体用法?PHP Image::setCore怎么用?PHP Image::setCore使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Intervention\Image\Image的用法示例。


在下文中一共展示了Image::setCore方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: execute

 /**
  * Reduces colors of a given image
  *
  * @param  \Intervention\Image\Image $image
  * @return boolean
  */
 public function execute($image)
 {
     $count = $this->argument(0)->value();
     $matte = $this->argument(1)->value();
     // get current image size
     $size = $image->getSize();
     // create empty canvas
     $resource = imagecreatetruecolor($size->width, $size->height);
     // define matte
     if (is_null($matte)) {
         $matte = imagecolorallocatealpha($resource, 255, 255, 255, 127);
     } else {
         $matte = $image->getDriver()->parseColor($matte)->getInt();
     }
     // fill with matte and copy original image
     imagefill($resource, 0, 0, $matte);
     // set transparency
     imagecolortransparent($resource, $matte);
     // copy original image
     imagecopy($resource, $image->getCore(), 0, 0, 0, 0, $size->width, $size->height);
     if (is_numeric($count) && $count <= 256) {
         // decrease colors
         imagetruecolortopalette($resource, true, $count);
     }
     // set new resource
     $image->setCore($resource);
     return true;
 }
开发者ID:shubhomoy,项目名称:evolve,代码行数:34,代码来源:LimitColorsCommand.php

示例2: applyFilter

 /**
  * Applies filter effects to the given image
  *
  * @param Image\Image $image The image to filter.
  *
  * @return Image\Image The filtered image.
  *
  * @throws FilterException if the image filter algorithm fails.
  */
 public function applyFilter(Image\Image $image)
 {
     if ($this->level <= 0) {
         $gd = $image->getCore();
         $width = imagesx($gd);
         $height = imagesy($gd);
         for ($x = 0; $x < $width; ++$x) {
             for ($y = 0; $y < $height; ++$y) {
                 $rgba = imagecolorsforindex($gd, imagecolorat($gd, $x, $y));
                 $r = $rgba['red'];
                 $g = $rgba['green'];
                 $b = $rgba['blue'];
                 $a = $rgba['alpha'];
                 $level = $this->level * -1;
                 $max = max($r, $g, $b);
                 $avg = ($r + $g + $b) / 3;
                 $amt = abs($max - $avg) * 2 / 255 * $level / 100;
                 if ($r !== $max) {
                     $r += ($max - $r) * $amt;
                 }
                 if ($g !== $max) {
                     $g += ($max - $g) * $amt;
                 }
                 if ($b !== $max) {
                     $b += ($max - $b) * $amt;
                 }
                 imagesetpixel($gd, $x, $y, imagecolorallocatealpha($gd, $r, $g, $b, $a));
             }
         }
         $image->setCore($gd);
     } else {
         $image->filter(new SaturateFilter($this->level));
     }
     return $image;
 }
开发者ID:BitmanNL,项目名称:traffictower-cms,代码行数:44,代码来源:VibranceFilter.php

示例3: execute

 /**
  * Reduces colors of a given image
  *
  * @param  \Intervention\Image\Image $image
  * @return boolean
  */
 public function execute($image)
 {
     $count = $this->argument(0)->value();
     $matte = $this->argument(1)->value();
     // get current image size
     $size = $image->getSize();
     // build 2 color alpha mask from original alpha
     $alpha = clone $image->getCore();
     $alpha->separateImageChannel(\Imagick::CHANNEL_ALPHA);
     $alpha->transparentPaintImage('#ffffff', 0, 0, false);
     $alpha->separateImageChannel(\Imagick::CHANNEL_ALPHA);
     $alpha->negateImage(false);
     if ($matte) {
         // get matte color
         $mattecolor = $image->getDriver()->parseColor($matte)->getPixel();
         // create matte image
         $canvas = new \Imagick();
         $canvas->newImage($size->width, $size->height, $mattecolor, 'png');
         // lower colors of original and copy to matte
         $image->getCore()->quantizeImage($count, \Imagick::COLORSPACE_RGB, 0, false, false);
         $canvas->compositeImage($image->getCore(), \Imagick::COMPOSITE_DEFAULT, 0, 0);
         // copy new alpha to canvas
         $canvas->compositeImage($alpha, \Imagick::COMPOSITE_COPYOPACITY, 0, 0);
         // replace core
         $image->setCore($canvas);
     } else {
         $image->getCore()->quantizeImage($count, \Imagick::COLORSPACE_RGB, 0, false, false);
         $image->getCore()->compositeImage($alpha, \Imagick::COMPOSITE_COPYOPACITY, 0, 0);
     }
     return true;
 }
开发者ID:hilmysyarif,项目名称:sic,代码行数:37,代码来源:LimitColorsCommand.php

示例4: applyFilter

 /**
  * Applies filter effects to the given image
  *
  * @param Image\Image $image The image to filter.
  *
  * @return Image\Image The filtered image.
  *
  * @throws FilterException if the image filter algorithm fails.
  */
 public function applyFilter(Image\Image $image)
 {
     $gd = $image->getCore();
     imagefilter($gd, IMG_FILTER_GRAYSCALE);
     imagefilter($gd, IMG_FILTER_COLORIZE, 60, 30, 0);
     $image->setCore($gd);
     return $image;
 }
开发者ID:BitmanNL,项目名称:traffictower-cms,代码行数:17,代码来源:SepiaFilter.php

示例5: applyFilter

 /**
  * Applies filter effects to the given image
  *
  * @param Image\Image $image The image to filter.
  *
  * @return Image\Image The filtered image.
  *
  * @throws FilterException if the image filter algorithm fails.
  */
 public function applyFilter(Image\Image $image)
 {
     $gd = $image->getCore();
     if (!imagefilter($gd, IMG_FILTER_EMBOSS)) {
         throw new FilterException('Er is een fout opgetreden bij het bewerken van de afbeelding. ' + 'Probeer het later alstublieft opnieuw.', 1);
     }
     $image->setCore($gd);
     return $image;
 }
开发者ID:BitmanNL,项目名称:traffictower-cms,代码行数:18,代码来源:EmbossFilter.php

示例6: execute

 /**
  * Resizes image boundaries
  *
  * @param  \Intervention\Image\Image $image
  * @return boolean
  */
 public function execute($image)
 {
     $width = $this->argument(0)->type('digit')->required()->value();
     $height = $this->argument(1)->type('digit')->required()->value();
     $anchor = $this->argument(2)->value('center');
     $relative = $this->argument(3)->type('boolean')->value();
     $bgcolor = $this->argument(4)->value();
     $original_width = $image->getWidth();
     $original_height = $image->getHeight();
     // check of only width or height is set
     $width = is_null($width) ? $original_width : intval($width);
     $height = is_null($height) ? $original_height : intval($height);
     // check on relative width/height
     if ($relative) {
         $width = $original_width + $width;
         $height = $original_height + $height;
     }
     // check for negative width/height
     $width = $width <= 0 ? $width + $original_width : $width;
     $height = $height <= 0 ? $height + $original_height : $height;
     // create new canvas
     $canvas = $image->getDriver()->newImage($width, $height, $bgcolor);
     // set copy position
     $canvas_size = $canvas->getSize()->align($anchor);
     $image_size = $image->getSize()->align($anchor);
     $canvas_pos = $image_size->relativePosition($canvas_size);
     $image_pos = $canvas_size->relativePosition($image_size);
     if ($width <= $original_width) {
         $dst_x = 0;
         $src_x = $canvas_pos->x;
         $src_w = $canvas_size->width;
     } else {
         $dst_x = $image_pos->x;
         $src_x = 0;
         $src_w = $original_width;
     }
     if ($height <= $original_height) {
         $dst_y = 0;
         $src_y = $canvas_pos->y;
         $src_h = $canvas_size->height;
     } else {
         $dst_y = $image_pos->y;
         $src_y = 0;
         $src_h = $original_height;
     }
     // make image area transparent to keep transparency
     // even if background-color is set
     $transparent = imagecolorallocatealpha($canvas->getCore(), 255, 255, 255, 127);
     imagealphablending($canvas->getCore(), false);
     // do not blend / just overwrite
     imagefilledrectangle($canvas->getCore(), $dst_x, $dst_y, $dst_x + $src_w - 1, $dst_y + $src_h - 1, $transparent);
     // copy image into new canvas
     imagecopy($canvas->getCore(), $image->getCore(), $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h);
     // set new core to canvas
     $image->setCore($canvas->getCore());
     return true;
 }
开发者ID:hilmysyarif,项目名称:sic,代码行数:63,代码来源:ResizeCanvasCommand.php

示例7: execute

 /**
  * Rotates image counter clockwise
  *
  * @param  \Intervention\Image\Image $image
  * @return boolean
  */
 public function execute($image)
 {
     $angle = $this->argument(0)->type('numeric')->required()->value();
     $color = $this->argument(1)->value();
     $color = new Color($color);
     // rotate image
     $image->setCore(imagerotate($image->getCore(), $angle, $color->getInt()));
     return true;
 }
开发者ID:hilmysyarif,项目名称:sic,代码行数:15,代码来源:RotateCommand.php

示例8: execute

 /**
  * Resets given image to its backup state
  *
  * @param  \Intervention\Image\Image $image
  * @return boolean
  */
 public function execute($image)
 {
     if (is_resource($backup = $image->getBackup())) {
         // destroy old resource
         imagedestroy($image->getCore());
         // reset to new resource
         $image->setCore($backup);
         return true;
     }
     throw new \Intervention\Image\Exception\RuntimeException("Backup not available. Call backup() before reset().");
 }
开发者ID:falexandre,项目名称:image,代码行数:17,代码来源:ResetCommand.php

示例9: execute

 /**
  * Resets given image to its backup state
  *
  * @param  \Intervention\Image\Image $image
  * @return boolean
  */
 public function execute($image)
 {
     $backup = $image->getBackup();
     if ($backup instanceof \Imagick) {
         // destroy old core
         $image->getCore()->clear();
         // reset to new resource
         $image->setCore($backup);
         return true;
     }
     throw new \Intervention\Image\Exception\RuntimeException("Backup not available. Call backup() before reset().");
 }
开发者ID:falexandre,项目名称:image,代码行数:18,代码来源:ResetCommand.php

示例10: execute

 /**
  * Applies an alpha mask to an image
  *
  * @param  \Intervention\Image\Image $image
  * @return boolean
  */
 public function execute($image)
 {
     $mask_source = $this->argument(0)->value();
     $mask_w_alpha = $this->argument(1)->type('bool')->value(false);
     $image_size = $image->getSize();
     // create empty canvas
     $canvas = $image->getDriver()->newImage($image_size->width, $image_size->height, array(0, 0, 0, 0));
     // build mask image from source
     $mask = $image->getDriver()->init($mask_source);
     $mask_size = $mask->getSize();
     // resize mask to size of current image (if necessary)
     if ($mask_size != $image_size) {
         $mask->resize($image_size->width, $image_size->height);
     }
     imagealphablending($canvas->getCore(), false);
     if (!$mask_w_alpha) {
         // mask from greyscale image
         imagefilter($mask->getCore(), IMG_FILTER_GRAYSCALE);
     }
     // redraw old image pixel by pixel considering alpha map
     for ($x = 0; $x < $image_size->width; $x++) {
         for ($y = 0; $y < $image_size->height; $y++) {
             $color = $image->pickColor($x, $y, 'array');
             $alpha = $mask->pickColor($x, $y, 'array');
             if ($mask_w_alpha) {
                 $alpha = $alpha[3];
                 // use alpha channel as mask
             } else {
                 if ($alpha[3] == 0) {
                     // transparent as black
                     $alpha = 0;
                 } else {
                     // $alpha = floatval(round((($alpha[0] + $alpha[1] + $alpha[3]) / 3) / 255, 2));
                     // image is greyscale, so channel doesn't matter (use red channel)
                     $alpha = floatval(round($alpha[0] / 255, 2));
                 }
             }
             // preserve alpha of original image...
             if ($color[3] < $alpha) {
                 $alpha = $color[3];
             }
             // replace alpha value
             $color[3] = $alpha;
             // redraw pixel
             $canvas->pixel($color, $x, $y);
         }
     }
     // replace current image with masked instance
     $image->setCore($canvas->getCore());
     return true;
 }
开发者ID:hilmysyarif,项目名称:sic,代码行数:57,代码来源:MaskCommand.php

示例11: execute

 /**
  * Resets given image to its backup state
  *
  * @param  \Intervention\Image\Image $image
  * @return boolean
  */
 public function execute($image)
 {
     $backupName = $this->argument(0)->value();
     if (is_resource($backup = $image->getBackup($backupName))) {
         // destroy current resource
         imagedestroy($image->getCore());
         // clone backup
         $backup = $image->getDriver()->cloneCore($backup);
         // reset to new resource
         $image->setCore($backup);
         return true;
     }
     throw new \Intervention\Image\Exception\RuntimeException("Backup not available. Call backup() before reset().");
 }
开发者ID:hilmysyarif,项目名称:sic,代码行数:20,代码来源:ResetCommand.php

示例12: execute

 /**
  * Resets given image to its backup state
  *
  * @param  \Intervention\Image\Image $image
  * @return boolean
  */
 public function execute($image)
 {
     $backupName = $this->argument(0)->value();
     $backup = $image->getBackup($backupName);
     if ($backup instanceof \Imagick) {
         // destroy current core
         $image->getCore()->clear();
         // clone backup
         $backup = clone $backup;
         // reset to new resource
         $image->setCore($backup);
         return true;
     }
     throw new \Intervention\Image\Exception\RuntimeException("Backup not available. Call backup({$backupName}) before reset().");
 }
开发者ID:hilmysyarif,项目名称:sic,代码行数:21,代码来源:ResetCommand.php

示例13: execute

 /**
  * Fills image with color or pattern
  *
  * @param  \Intervention\Image\Image $image
  * @return boolean
  */
 public function execute($image)
 {
     $filling = $this->argument(0)->value();
     $x = $this->argument(1)->type('digit')->value();
     $y = $this->argument(2)->type('digit')->value();
     $width = $image->getWidth();
     $height = $image->getHeight();
     $resource = $image->getCore();
     try {
         // set image tile filling
         $source = new Decoder();
         $tile = $source->init($filling);
         imagesettile($image->getCore(), $tile->getCore());
         $filling = IMG_COLOR_TILED;
     } catch (\Intervention\Image\Exception\NotReadableException $e) {
         // set solid color filling
         $color = new Color($filling);
         $filling = $color->getInt();
     }
     imagealphablending($resource, true);
     if (is_int($x) && is_int($y)) {
         // resource should be visible through transparency
         $base = $image->getDriver()->newImage($width, $height)->getCore();
         imagecopy($base, $resource, 0, 0, 0, 0, $width, $height);
         // floodfill if exact position is defined
         imagefill($resource, $x, $y, $filling);
         // copy filled original over base
         imagecopy($base, $resource, 0, 0, 0, 0, $width, $height);
         // set base as new resource-core
         $image->setCore($base);
         imagedestroy($resource);
     } else {
         // fill whole image otherwise
         imagefilledrectangle($resource, 0, 0, $width - 1, $height - 1, $filling);
     }
     isset($tile) ? imagedestroy($tile->getCore()) : null;
     return true;
 }
开发者ID:hilmysyarif,项目名称:sic,代码行数:44,代码来源:FillCommand.php

示例14: applyFilter

 /**
  * Applies filter effects to the given image
  *
  * @param Image\Image $image The image to filter.
  *
  * @return Image\Image The filtered image.
  *
  * @throws FilterException if the image filter algorithm fails.
  */
 public function applyFilter(Image\Image $image)
 {
     $gd = $image->getCore();
     $width = imagesx($gd);
     $height = imagesy($gd);
     for ($x = 0; $x < $width; ++$x) {
         for ($y = 0; $y < $height; ++$y) {
             $rgba = imagecolorsforindex($gd, imagecolorat($gd, $x, $y));
             $r = $rgba['red'];
             $g = $rgba['green'];
             $b = $rgba['blue'];
             $a = $rgba['alpha'];
             list($h, $s, $l) = ColorConverter::rgbToHsl($r, $g, $b);
             $h += $this->hue / 100;
             if ($h > 1.0) {
                 $h -= 1.0;
             }
             list($r, $g, $b) = ColorConverter::hslToRgb($h, $s, $l);
             imagesetpixel($gd, $x, $y, imagecolorallocatealpha($gd, $r, $g, $b, $s));
         }
     }
     $image->setCore($gd);
     return $image;
 }
开发者ID:BitmanNL,项目名称:traffictower-cms,代码行数:33,代码来源:HueFilter.php

示例15: execute

 /**
  * Fills image with color or pattern
  *
  * @param  \Intervention\Image\Image $image
  * @return boolean
  */
 public function execute($image)
 {
     $filling = $this->argument(0)->value();
     $x = $this->argument(1)->type('digit')->value();
     $y = $this->argument(2)->type('digit')->value();
     $imagick = $image->getCore();
     try {
         // set image filling
         $source = new Decoder();
         $filling = $source->init($filling);
     } catch (\Intervention\Image\Exception\NotReadableException $e) {
         // set solid color filling
         $filling = new Color($filling);
     }
     // flood fill if coordinates are set
     if (is_int($x) && is_int($y)) {
         // flood fill with texture
         if ($filling instanceof Image) {
             // create tile
             $tile = clone $image->getCore();
             // mask away color at position
             $tile->transparentPaintImage($tile->getImagePixelColor($x, $y), 0, 0, false);
             // create canvas
             $canvas = clone $image->getCore();
             // fill canvas with texture
             $canvas = $canvas->textureImage($filling->getCore());
             // merge canvas and tile
             $canvas->compositeImage($tile, \Imagick::COMPOSITE_DEFAULT, 0, 0);
             // replace image core
             $image->setCore($canvas);
             // flood fill with color
         } elseif ($filling instanceof Color) {
             // create canvas with filling
             $canvas = new \Imagick();
             $canvas->newImage($image->getWidth(), $image->getHeight(), $filling->getPixel(), 'png');
             // create tile to put on top
             $tile = clone $image->getCore();
             // mask away color at pos.
             $tile->transparentPaintImage($tile->getImagePixelColor($x, $y), 0, 0, false);
             // save alpha channel of original image
             $alpha = clone $image->getCore();
             // merge original with canvas and tile
             $image->getCore()->compositeImage($canvas, \Imagick::COMPOSITE_DEFAULT, 0, 0);
             $image->getCore()->compositeImage($tile, \Imagick::COMPOSITE_DEFAULT, 0, 0);
             // restore alpha channel of original image
             $image->getCore()->compositeImage($alpha, \Imagick::COMPOSITE_COPYOPACITY, 0, 0);
         }
     } else {
         if ($filling instanceof Image) {
             // fill whole image with texture
             $image->setCore($image->getCore()->textureImage($filling->getCore()));
         } elseif ($filling instanceof Color) {
             // fill whole image with color
             $draw = new \ImagickDraw();
             $draw->setFillColor($filling->getPixel());
             $draw->rectangle(0, 0, $image->getWidth(), $image->getHeight());
             $image->getCore()->drawImage($draw);
         }
     }
     return true;
 }
开发者ID:manhvu1212,项目名称:videoplatform,代码行数:67,代码来源:FillCommand.php


注:本文中的Intervention\Image\Image::setCore方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。