本文整理汇总了PHP中Intervention\Image\Image::getSize方法的典型用法代码示例。如果您正苦于以下问题:PHP Image::getSize方法的具体用法?PHP Image::getSize怎么用?PHP Image::getSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Intervention\Image\Image
的用法示例。
在下文中一共展示了Image::getSize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
// get imagick
$imagick = $image->getCore();
// build mask image from source
$mask = $image->getDriver()->init($mask_source);
// resize mask to size of current image (if necessary)
$image_size = $image->getSize();
if ($mask->getSize() != $image_size) {
$mask->resize($image_size->width, $image_size->height);
}
$imagick->setImageMatte(true);
if ($mask_w_alpha) {
// just mask with alpha map
$imagick->compositeImage($mask->getCore(), \Imagick::COMPOSITE_DSTIN, 0, 0);
} else {
// get alpha channel of original as greyscale image
$original_alpha = clone $imagick;
$original_alpha->separateImageChannel(\Imagick::CHANNEL_ALPHA);
// use red channel from mask ask alpha
$mask_alpha = clone $mask->getCore();
$mask_alpha->compositeImage($mask->getCore(), \Imagick::COMPOSITE_DEFAULT, 0, 0);
// $mask_alpha->setImageAlphaChannel(\Imagick::ALPHACHANNEL_DEACTIVATE);
$mask_alpha->separateImageChannel(\Imagick::CHANNEL_ALL);
// combine both alphas from original and mask
$original_alpha->compositeImage($mask_alpha, \Imagick::COMPOSITE_COPYOPACITY, 0, 0);
// mask the image with the alpha combination
$imagick->compositeImage($original_alpha, \Imagick::COMPOSITE_DSTIN, 0, 0);
}
return true;
}
示例2: 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;
}
示例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;
}
示例4: 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;
}
示例5: execute
/**
* Resizes image dimensions
*
* @param \Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
$width = $this->argument(0)->value();
$height = $this->argument(1)->value();
$constraints = $this->argument(2)->type('closure')->value();
// resize box
$resized = $image->getSize()->resize($width, $height, $constraints);
// modify image
$this->modify($image, 0, 0, 0, 0, $resized->getWidth(), $resized->getHeight(), $image->getWidth(), $image->getHeight());
return true;
}
示例6: execute
/**
* Resizes image dimensions
*
* @param \Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
$width = $this->argument(0)->value();
$height = $this->argument(1)->value();
$constraints = $this->argument(2)->type('closure')->value();
// resize box
$resized = $image->getSize()->resize($width, $height, $constraints);
// modify image
$image->getCore()->resizeImage($resized->getWidth(), $resized->getHeight(), \Imagick::FILTER_BOX, 1);
return true;
}
示例7: execute
/**
* Saves a backups of current state of image core
*
* @param \Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
// clone current image resource
$size = $image->getSize();
$clone = imagecreatetruecolor($size->width, $size->height);
imagealphablending($clone, false);
imagesavealpha($clone, true);
imagecopy($clone, $image->getCore(), 0, 0, 0, 0, $size->width, $size->height);
$image->setBackup($clone);
return true;
}
示例8: execute
/**
* Calculates checksum of given image
*
* @param \Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
$colors = array();
$size = $image->getSize();
for ($x = 0; $x <= $size->width - 1; $x++) {
for ($y = 0; $y <= $size->height - 1; $y++) {
$colors[] = $image->pickColor($x, $y, 'array');
}
}
$this->setOutput(md5(serialize($colors)));
return true;
}
示例9: execute
/**
* Defines opacity of an image
*
* @param \Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
$transparency = $this->argument(0)->between(0, 100)->required()->value();
// get size of image
$size = $image->getSize();
// build temp alpha mask
$mask_color = sprintf('rgba(0, 0, 0, %.1f)', $transparency / 100);
$mask = $image->getDriver()->newImage($size->width, $size->height, $mask_color);
// mask image
$image->mask($mask->getCore(), true);
return true;
}
示例10: execute
/**
* Crops and resized an image at the same time
*
* @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')->value($width);
$constraints = $this->argument(2)->type('closure')->value();
// calculate size
$cropped = $image->getSize()->fit(new Size($width, $height));
$resized = clone $cropped;
$resized = $resized->resize($width, $height, $constraints);
// modify image
$this->modify($image, 0, 0, $cropped->pivot->x, $cropped->pivot->y, $resized->getWidth(), $resized->getHeight(), $cropped->getWidth(), $cropped->getHeight());
return true;
}
示例11: execute
/**
* Resizes image dimensions
*
* @param \Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
$width = $this->argument(0)->value();
$height = $this->argument(1)->value();
$constraints = $this->argument(2)->type('closure')->value();
// resize box
$resized = $image->getSize()->resize($width, $height, $constraints);
// modify image
foreach ($image as $frame) {
$frame->getCore()->scaleImage($resized->getWidth(), $resized->getHeight());
}
return true;
}
示例12: 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;
}
示例13: execute
/**
* Insert another image into given image
*
* @param \Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
$source = $this->argument(0)->required()->value();
$position = $this->argument(1)->type('string')->value();
$x = $this->argument(2)->type('digit')->value(0);
$y = $this->argument(3)->type('digit')->value(0);
// build watermark
$watermark = $image->getDriver()->init($source);
// define insertion point
$image_size = $image->getSize()->align($position, $x, $y);
$watermark_size = $watermark->getSize()->align($position);
$target = $image_size->relativePosition($watermark_size);
// insert image at position
return $image->getCore()->compositeImage($watermark->getCore(), \Imagick::COMPOSITE_DEFAULT, $target->x, $target->y);
}
示例14: execute
/**
* Saves a backups of current state of image core
*
* @param \Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
$backupName = $this->argument(0)->value();
// clone current image resource
$size = $image->getSize();
$clone = imagecreatetruecolor($size->width, $size->height);
imagealphablending($clone, false);
imagesavealpha($clone, true);
$transparency = imagecolorallocatealpha($clone, 0, 0, 0, 127);
imagefill($clone, 0, 0, $transparency);
// copy image to clone
imagecopy($clone, $image->getCore(), 0, 0, 0, 0, $size->width, $size->height);
$image->setBackup($clone, $backupName);
return true;
}
示例15: execute
/**
* Insert another image into given image
*
* @param \Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
$source = $this->argument(0)->required()->value();
$position = $this->argument(1)->type('string')->value();
$x = $this->argument(2)->type('digit')->value(0);
$y = $this->argument(3)->type('digit')->value(0);
// build watermark
$watermark = $image->getDriver()->init($source);
// define insertion point
$image_size = $image->getSize()->align($position, $x, $y);
$watermark_size = $watermark->getSize()->align($position);
$target = $image_size->relativePosition($watermark_size);
// insert image at position
imagealphablending($image->getCore(), true);
return imagecopy($image->getCore(), $watermark->getCore(), $target->x, $target->y, 0, 0, $watermark_size->width, $watermark_size->height);
}