本文整理匯總了PHP中Imagick::setFormat方法的典型用法代碼示例。如果您正苦於以下問題:PHP Imagick::setFormat方法的具體用法?PHP Imagick::setFormat怎麽用?PHP Imagick::setFormat使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Imagick
的用法示例。
在下文中一共展示了Imagick::setFormat方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: animate
/**
* {@inheritdoc}
*/
public function animate($format, $delay, $loops)
{
if ('gif' !== strtolower($format)) {
throw new InvalidArgumentException('Animated picture is currently only supported on gif');
}
if (!is_int($loops) || $loops < 0) {
throw new InvalidArgumentException('Loops must be a positive integer.');
}
if (null !== $delay && (!is_int($delay) || $delay < 0)) {
throw new InvalidArgumentException('Delay must be either null or a positive integer.');
}
try {
foreach ($this as $offset => $layer) {
$this->resource->setIteratorIndex($offset);
$this->resource->setFormat($format);
if (null !== $delay) {
$this->resource->setImageDelay($delay / 10);
$this->resource->setImageTicksPerSecond(100);
}
$this->resource->setImageIterations($loops);
$this->resource->setImage($layer->getImagick());
}
} catch (\ImagickException $e) {
throw new RuntimeException('Failed to animate layers', $e->getCode(), $e);
}
return $this;
}
示例2: _render
/**
* Render the image to data string.
* @param string $format
* @param integer|null $quality
* @return string
*/
protected function _render($format, $quality)
{
$format = $this->getFormat($format, $quality);
$this->im->setFormat($format);
if (isset($quality)) {
$this->im->setImageCompressionQuality($quality);
}
return (string) $this->im;
}
示例3: resizeImagick
/**
* Функция создания квадратного изображения с кадрированием.
* @param string $sourceFile - путь до исходного файла
* @param string $destinationFile - путь файла, в который сохраняется результат
* @param integer $width
* @param integer $height
* @return
*/
function resizeImagick($sourceFile, $destinationFile, $width, $height, $resultType = 'gif')
{
$info = getimagesize($sourceFile);
$destinationFile = $destinationFile;
if (false === in_array($info[2], array(IMAGETYPE_JPEG, IMAGETYPE_GIF, IMAGETYPE_PNG))) {
return false;
}
$originalWidth = $info[0];
$originalHeight = $info[1];
$ratio_orig = $originalWidth / $originalHeight;
if ($width / $height > $ratio_orig) {
$width = round($height * $ratio_orig);
} else {
$height = round($width / $ratio_orig);
}
if ($originalWidth < $width) {
$height = $originalHeight;
$width = $originalWidth;
}
$newWidth = $width;
$newHeight = $height;
$biggestSideSize = max($newWidth, $newHeight);
# создаём новый пустой объект
$newFileObj = new \Imagick();
# оригинальное изображение
$im = new \Imagick($sourceFile);
switch ($info[2]) {
case IMAGETYPE_GIF:
$im->setFormat("gif");
foreach ($im as $animation) {
$animation->thumbnailImage($newWidth, $newHeight);
//Выполняется resize до 200 пикселей поширине и сколько получится по высоте (с соблюдением пропорций конечно)
$animation->setImagePage($animation->getImageWidth(), $animation->getImageHeight(), 0, 0);
}
$im->writeImages($destinationFile, true);
return image_type_to_extension($info[2], false);
break;
case IMAGETYPE_PNG:
$im = $im->coalesceImages();
$im->setFormat("gif");
$im->thumbnailImage($newWidth, $newHeight);
$im->writeImages($destinationFile, true);
return image_type_to_extension($info[2], false);
break;
case IMAGETYPE_JPEG:
$im = $im->coalesceImages();
$im->setFormat("gif");
$im->thumbnailImage($newWidth, $newHeight);
$im->writeImages($destinationFile, true);
return image_type_to_extension($info[2], false);
break;
default:
die($info[2] . 'd');
}
}
示例4: getSilhouette
function getSilhouette(\Imagick $imagick)
{
$character = new \Imagick();
$character->newPseudoImage($imagick->getImageWidth(), $imagick->getImageHeight(), "canvas:white");
$canvas = new \Imagick();
$canvas->newPseudoImage($imagick->getImageWidth(), $imagick->getImageHeight(), "canvas:black");
$character->compositeimage($imagick, \Imagick::COMPOSITE_COPYOPACITY, 0, 0);
$canvas->compositeimage($character, \Imagick::COMPOSITE_ATOP, 0, 0);
$canvas->setFormat('png');
return $canvas;
}
示例5: createAnimation
/**
* Generate the animated gif
*
* @return string binary image data
*/
private function createAnimation($images)
{
$animation = new \Imagick();
$animation->setFormat('gif');
foreach ($images as $image) {
$frame = new \Imagick();
$frame->readImageBlob($image);
$animation->addImage($frame);
$animation->setImageDelay(50);
}
return $animation->getImagesBlob();
}
示例6: using_imagick
function using_imagick()
{
global $image, $mask, $clut, $final, $qual;
$im = new Imagick($image);
# Apply color lookup table
$im->clutImage(new Imagick($clut));
# Apply transparency mask
$im->compositeImage(new Imagick($mask), imagick::COMPOSITE_COPYOPACITY, 0, 0);
# Save the image
$im->setCompressionQuality($qual);
$im->setImageDepth(8);
$im->setFormat("png");
$im->writeImage($final);
}
示例7: animate
/**
* {@inheritdoc}
*/
public function animate($format, $delay, $loops)
{
if ('gif' !== strtolower($format)) {
throw new InvalidArgumentException('Animated picture is currently only supported on gif');
}
foreach (array('Loops' => $loops, 'Delay' => $delay) as $name => $value) {
if (!is_int($value) || $value < 0) {
throw new InvalidArgumentException(sprintf('%s must be a positive integer.', $name));
}
}
try {
foreach ($this as $offset => $layer) {
$this->resource->setIteratorIndex($offset);
$this->resource->setFormat($format);
$this->resource->setImageDelay($delay / 10);
$this->resource->setImageTicksPerSecond(100);
$this->resource->setImageIterations($loops);
}
} catch (\ImagickException $e) {
throw new RuntimeException('Failed to animate layers', $e->getCode(), $e);
}
return $this;
}
示例8: renderCustomImage
function renderCustomImage()
{
$size = 400;
$imagick1 = new \Imagick();
//$imagick1->newPseudoImage($size, $size, 'gradient:black-white');
$imagick1->setColorspace(\Imagick::COLORSPACE_GRAY);
//$imagick1->setColorspace(\Imagick::COLORSPACE_RGB);
//$imagick1->setColorspace(\Imagick::COLORSPACE_SRGB);
$imagick1->setColorspace(\Imagick::COLORSPACE_CMYK);
$imagick1->newPseudoImage($size, $size, 'gradient:gray(100%)-gray(0%)');
$imagick1->setFormat('png');
//analyzeImage($imagick1);
header("Content-Type: image/png");
echo $imagick1->getImageBlob();
}
示例9: _generateImage
protected function _generateImage($text, $filePath)
{
$image = new Imagick();
$draw = new ImagickDraw();
$draw->setFont('lib/SwiftOtter/OpenSans-Regular.ttf');
$draw->setFontSize('13');
$metrics = $image->queryFontMetrics($draw, $text, false);
$width = 100;
$padding = 10;
if (isset($metrics['textWidth'])) {
$width = $metrics['textWidth'] + $padding * 2;
}
$image->newImage($width, 17, new ImagickPixel('#f98b25'));
$draw->setFillColor('#ffffff');
$image->annotateImage($draw, $padding / 2 + 3, $padding + 3, 0, $text);
$draw->setFillColor('#a04300');
$image->borderImage('#a04300', 1, 1);
$image->setFormat('gif');
$image->writeImage($filePath);
return $image;
}
示例10: save
/**
* @param string $file
* @param int $quality
*
* @throws \ManaPHP\Image\Adapter\Exception
*/
public function save($file, $quality = 80)
{
$file = $this->alias->resolve($file);
$ext = strtolower(pathinfo($file, PATHINFO_EXTENSION));
$this->_image->setFormat($ext);
if ($ext === 'gif') {
$this->_image->optimizeImageLayers();
} else {
if ($ext === 'jpg' || $ext === 'jpeg') {
$this->_image->setImageCompression(\Imagick::COMPRESSION_JPEG);
$this->_image->setImageCompressionQuality($quality);
}
}
$dir = dirname($file);
if (!@mkdir($dir, 0755, true) && !is_dir($dir)) {
throw new ImagickException('create `:dir` image directory failed: :message', ['dir' => $dir, 'message' => error_get_last()['message']]);
}
if (!$this->_image->writeImage($file)) {
throw new ImagickException('save `:file` image file failed', ['file' => $file]);
}
}
示例11: intval
<?php
$imagick = new \Imagick();
$desiredWidth = 300;
$desiredWidth = 2 * intval($desiredWidth / 2);
$imagick->newpseudoimage($desiredWidth / 2, 1, "gradient:white-black");
$imagick->setFormat('png');
$imagick->setImageVirtualPixelMethod(\Imagick::VIRTUALPIXELMETHOD_MIRROR);
$originalWidth = $imagick->getImageWidth();
//Now scale, rotate, translate (aka affine project) it
//to be how you want
$points = array($originalWidth / $desiredWidth, 0, 0, 1, 0, 0);
//Make the image be the desired width.
$imagick->sampleimage($desiredWidth, $imagick->getImageHeight());
$imagick->distortImage(\Imagick::DISTORTION_AFFINEPROJECTION, $points, false);
header("Content-Type: image/png");
echo $imagick->getImageBlob();
示例12: addImagePngAlpha
protected function addImagePngAlpha($file, $x, $y, $w, $h, $byte)
{
// generate images
$img = imagecreatefrompng($file);
if ($img === false) {
return;
}
// FIXME The pixel transformation doesn't work well with 8bit PNGs
$eight_bit = ($byte & 4) !== 4;
$wpx = imagesx($img);
$hpx = imagesy($img);
imagesavealpha($img, false);
// create temp alpha file
$tempfile_alpha = tempnam($this->tmp, "cpdf_img_");
@unlink($tempfile_alpha);
$tempfile_alpha = "{$tempfile_alpha}.png";
// create temp plain file
$tempfile_plain = tempnam($this->tmp, "cpdf_img_");
@unlink($tempfile_plain);
$tempfile_plain = "{$tempfile_plain}.png";
$imgalpha = imagecreate($wpx, $hpx);
imagesavealpha($imgalpha, false);
// generate gray scale palette (0 -> 255)
for ($c = 0; $c < 256; ++$c) {
imagecolorallocate($imgalpha, $c, $c, $c);
}
// Use PECL gmagick + Graphics Magic to process transparent PNG images
if (extension_loaded("gmagick")) {
$gmagick = new Gmagick($file);
$gmagick->setimageformat('png');
// Get opacity channel (negative of alpha channel)
$alpha_channel_neg = clone $gmagick;
$alpha_channel_neg->separateimagechannel(Gmagick::CHANNEL_OPACITY);
// Negate opacity channel
$alpha_channel = new Gmagick();
$alpha_channel->newimage($wpx, $hpx, "#FFFFFF", "png");
$alpha_channel->compositeimage($alpha_channel_neg, Gmagick::COMPOSITE_DIFFERENCE, 0, 0);
$alpha_channel->separateimagechannel(Gmagick::CHANNEL_RED);
$alpha_channel->writeimage($tempfile_alpha);
// Cast to 8bit+palette
$imgalpha_ = imagecreatefrompng($tempfile_alpha);
imagecopy($imgalpha, $imgalpha_, 0, 0, 0, 0, $wpx, $hpx);
imagedestroy($imgalpha_);
imagepng($imgalpha, $tempfile_alpha);
// Make opaque image
$color_channels = new Gmagick();
$color_channels->newimage($wpx, $hpx, "#FFFFFF", "png");
$color_channels->compositeimage($gmagick, Gmagick::COMPOSITE_COPYRED, 0, 0);
$color_channels->compositeimage($gmagick, Gmagick::COMPOSITE_COPYGREEN, 0, 0);
$color_channels->compositeimage($gmagick, Gmagick::COMPOSITE_COPYBLUE, 0, 0);
$color_channels->writeimage($tempfile_plain);
$imgplain = imagecreatefrompng($tempfile_plain);
} elseif (extension_loaded("imagick")) {
$imagick = new Imagick($file);
$imagick->setFormat('png');
// Get opacity channel (negative of alpha channel)
$alpha_channel = clone $imagick;
$alpha_channel->separateImageChannel(Imagick::CHANNEL_ALPHA);
$alpha_channel->negateImage(true);
$alpha_channel->writeImage($tempfile_alpha);
// Cast to 8bit+palette
$imgalpha_ = imagecreatefrompng($tempfile_alpha);
imagecopy($imgalpha, $imgalpha_, 0, 0, 0, 0, $wpx, $hpx);
imagedestroy($imgalpha_);
imagepng($imgalpha, $tempfile_alpha);
// Make opaque image
$color_channels = new Imagick();
$color_channels->newImage($wpx, $hpx, "#FFFFFF", "png");
$color_channels->compositeImage($imagick, Imagick::COMPOSITE_COPYRED, 0, 0);
$color_channels->compositeImage($imagick, Imagick::COMPOSITE_COPYGREEN, 0, 0);
$color_channels->compositeImage($imagick, Imagick::COMPOSITE_COPYBLUE, 0, 0);
$color_channels->writeImage($tempfile_plain);
$imgplain = imagecreatefrompng($tempfile_plain);
} else {
// allocated colors cache
$allocated_colors = array();
// extract alpha channel
for ($xpx = 0; $xpx < $wpx; ++$xpx) {
for ($ypx = 0; $ypx < $hpx; ++$ypx) {
$color = imagecolorat($img, $xpx, $ypx);
$col = imagecolorsforindex($img, $color);
$alpha = $col['alpha'];
if ($eight_bit) {
// with gamma correction
$gammacorr = 2.2;
$pixel = pow((127 - $alpha) * 255 / 127 / 255, $gammacorr) * 255;
} else {
// without gamma correction
$pixel = (127 - $alpha) * 2;
$key = $col['red'] . $col['green'] . $col['blue'];
if (!isset($allocated_colors[$key])) {
$pixel_img = imagecolorallocate($img, $col['red'], $col['green'], $col['blue']);
$allocated_colors[$key] = $pixel_img;
} else {
$pixel_img = $allocated_colors[$key];
}
imagesetpixel($img, $xpx, $ypx, $pixel_img);
}
imagesetpixel($imgalpha, $xpx, $ypx, $pixel);
}
//.........這裏部分代碼省略.........
示例13: getImageData
/**
* Return raw image data.
*
* @param string $pathToImage
*
* @return \Imagick
*/
public function getImageData($pathToImage)
{
$imagick = new \Imagick();
$imagick->setResolution($this->resolution, $this->resolution);
$imagick->readImage(sprintf('%s[%s]', $this->pdfFile, $this->page - 1));
$imagick->mergeImageLayers(\Imagick::LAYERMETHOD_FLATTEN);
$imagick->setFormat($this->determineOutputFormat($pathToImage));
return $imagick;
}
示例14: Imagick
} else {
$favorites = 0;
}
if ($row['FAVORITES'] == NULL) {
$favorites = 0;
}
if ($row['FILE'] != "gif") {
$thumb_fn = $setting['image_output'] . 'thumbnails/' . $row['ID'] . '.jpg';
} else {
$thumb_fn = $setting['image_output'] . 'thumbnails/' . $row['ID'] . '.gif';
}
if (!file_exists($thumb_fn)) {
$image = new Imagick();
$image->readImage($setting['image_output'] . $row['ID'] . "." . $row['FILE']);
if ($row['FILE'] != "gif") {
$image->setFormat("jpg");
$image->setImageCompression(Imagick::COMPRESSION_JPEG);
$image->setImageCompressionQuality($setting['thumbnail_quality']);
$image->thumbnailImage($setting['thumbnail_size'], 0);
$image->writeImage($thumb_fn);
} else {
$image->setFormat("gif");
$image = $image->coalesceImages();
foreach ($image as $frame) {
$frame->thumbnailImage($setting['thumbnail_size'], 0);
$frame->setImagePage($setting['thumbnail_size'], 0, 0, 0);
}
$image = $image->deconstructImages();
$image->writeImages($thumb_fn, true);
}
$image->clear();
示例15: animate
/**
* {@inheritdoc}
*/
public function animate(array $frames, $delay = 20)
{
$gif = new \Imagick();
$gif->setFormat('gif');
foreach ($frames as $im) {
if ($im instanceof Imanee) {
$frame = $im->getResource()->getResource();
} else {
$frame = new \Imagick($im);
}
$frame->setImageDelay($delay);
$gif->addImage($frame);
}
$imagickResource = new ImagickResource();
$imagickResource->setResource($gif);
$imanee = new Imanee();
$imanee->setResource($imagickResource);
$imanee->setFormat('gif');
return $imanee;
}