本文整理匯總了PHP中Imagick::writeImages方法的典型用法代碼示例。如果您正苦於以下問題:PHP Imagick::writeImages方法的具體用法?PHP Imagick::writeImages怎麽用?PHP Imagick::writeImages使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Imagick
的用法示例。
在下文中一共展示了Imagick::writeImages方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: save
/**
* 保存圖像
* @param string $imgname 圖像保存名稱
* @param string $type 圖像類型
* @param boolean $interlace 是否對JPEG類型圖像設置隔行掃描
* @throws \Exception
*/
public function save($imgname, $type = NULL, $interlace = true)
{
if (empty($this->img)) {
throw new \Exception(_('No image resources can be saved'));
}
//設置圖片類型
if (is_null($type)) {
$type = $this->info['type'];
} else {
$type = strtolower($type);
$this->img->setImageFormat($type);
}
//JPEG圖像設置隔行掃描
if ('jpeg' == $type || 'jpg' == $type) {
$this->img->setImageInterlaceScheme(1);
}
//去除圖像配置信息
$this->img->stripImage();
//保存圖像
$imgname = realpath(dirname($imgname)) . '/' . basename($imgname);
//強製絕對路徑
if ('gif' == $type) {
$this->img->writeImages($imgname, true);
} else {
$this->img->writeImage($imgname);
}
}
示例2: save
public function save($file, $gray = false, $quality = 100)
{
if ($gray) {
$this->gray();
}
$res = $this->image->writeImages($file, true);
$this->image->clear();
$this->image->destroy();
return $res;
}
示例3: createAvatarAutomatically
/**
* アバター自動生成処理
*
* @param Model $model ビヘイビア呼び出し元モデル
* @param array $user ユーザデータ配列
* @return mixed On success Model::$data, false on failure
* @throws InternalErrorException
*/
public function createAvatarAutomatically(Model $model, $user)
{
//imagickdraw オブジェクトを作成します
$draw = new ImagickDraw();
//文字色のセット
$draw->setfillcolor('white');
//フォントサイズを 160 に設定します
$draw->setFontSize(140);
//テキストを追加します
$draw->setFont(CakePlugin::path($model->plugin) . 'webroot' . DS . 'fonts' . DS . 'ipaexg.ttf');
$draw->annotation(19, 143, mb_substr(mb_convert_kana($user['User']['handlename'], 'KVA'), 0, 1));
//新しいキャンバスオブジェクトを作成する
$canvas = new Imagick();
//ランダムで背景色を指定する
$red1 = strtolower(dechex(mt_rand(3, 12)));
$red2 = strtolower(dechex(mt_rand(0, 15)));
$green1 = strtolower(dechex(mt_rand(3, 12)));
$green2 = strtolower(dechex(mt_rand(0, 15)));
$blue1 = strtolower(dechex(mt_rand(3, 12)));
$blue2 = strtolower(dechex(mt_rand(0, 15)));
$canvas->newImage(179, 179, '#' . $red1 . $red2 . $green1 . $green2 . $blue1 . $blue2);
//ImagickDraw をキャンバス上に描畫します
$canvas->drawImage($draw);
//フォーマットを PNG に設定します
$canvas->setImageFormat('png');
App::uses('TemporaryFolder', 'Files.Utility');
$folder = new TemporaryFolder();
$filePath = $folder->path . DS . Security::hash($user['User']['handlename'], 'md5') . '.png';
$canvas->writeImages($filePath, true);
return $filePath;
}
示例4: save
/**
* {@inheritdoc}
*
* @return ImageInterface
*/
public function save($path = null, array $options = array())
{
$path = null === $path ? $this->imagick->getImageFilename() : $path;
if (null === $path) {
throw new RuntimeException('You can omit save path only if image has been open from a file');
}
try {
$this->prepareOutput($options, $path);
/** BEGIN CORE HACK */
// If a specific PNG format is requested, set it
if (isset($options['png_format'])) {
// Unless it's PNG8. Then we attempt to force Imagick to save it
// as PNG, that is palette-based with transparency
if ($options['png_format'] == 'png8') {
$this->imagick->quantizeImage(255, \Imagick::COLORSPACE_YUV, 8, false, false);
} else {
$path = (isset($options['png_format']) ? $options['png_format'] . ':' : '') . $path;
}
}
/** END CORE HACK */
$this->imagick->writeImages($path, true);
} catch (\ImagickException $e) {
throw new RuntimeException('Save operation failed', $e->getCode(), $e);
}
return $this;
}
示例5: image
private static function image($frame, $pixelPerPoint = 4, $outerFrame = 4, $format = "png", $quality = 85, $filename = FALSE, $save = TRUE, $print = false)
{
$imgH = count($frame);
$imgW = strlen($frame[0]);
$col[0] = new \ImagickPixel("white");
$col[1] = new \ImagickPixel("black");
$image = new \Imagick();
$image->newImage($imgW, $imgH, $col[0]);
$image->setCompressionQuality($quality);
$image->setImageFormat($format);
$draw = new \ImagickDraw();
$draw->setFillColor($col[1]);
for ($y = 0; $y < $imgH; $y++) {
for ($x = 0; $x < $imgW; $x++) {
if ($frame[$y][$x] == '1') {
$draw->point($x, $y);
}
}
}
$image->drawImage($draw);
$image->borderImage($col[0], $outerFrame, $outerFrame);
$image->scaleImage(($imgW + 2 * $outerFrame) * $pixelPerPoint, 0);
if ($save) {
if ($filename === false) {
throw new Exception("QR Code filename can't be empty");
}
$image->writeImages($filename, true);
}
if ($print) {
Header("Content-type: image/" . $format);
echo $image;
}
}
示例6: output
/**
* Outputs the image.
*
* @see XenForo_Image_Abstract::output()
*/
public function output($outputType, $outputFile = null, $quality = 85)
{
$this->_image->stripImage();
// NULL means output directly
switch ($outputType) {
case IMAGETYPE_GIF:
if (is_callable(array($this->_image, 'optimizeimagelayers'))) {
$this->_image->optimizeimagelayers();
}
$success = $this->_image->setImageFormat('gif');
break;
case IMAGETYPE_JPEG:
$success = $this->_image->setImageFormat('jpeg') && $this->_image->setImageCompression(Imagick::COMPRESSION_JPEG) && $this->_image->setImageCompressionQuality($quality);
break;
case IMAGETYPE_PNG:
$success = $this->_image->setImageFormat('png');
break;
default:
throw new XenForo_Exception('Invalid output type given. Expects IMAGETYPE_XXX constant.');
}
try {
if ($success) {
if (!$outputFile) {
echo $this->_image->getImagesBlob();
} else {
$success = $this->_image->writeImages($outputFile, true);
}
}
} catch (ImagickException $e) {
return false;
}
return $success;
}
示例7: save
/**
* {@inheritdoc}
*/
public function save($path, array $options = array())
{
try {
$this->prepareOutput($options);
$this->imagick->writeImages($path, true);
} catch (\ImagickException $e) {
throw new RuntimeException('Save operation failed', $e->getCode(), $e);
}
return $this;
}
示例8: processFileToImageCache
/**
* Write a rendered PDF to the cache.
*
* @param $filePath
* @param $cacheLocation
*/
protected function processFileToImageCache($filePath, $cacheLocation)
{
if (!is_dir($cacheLocation)) {
mkdir($cacheLocation);
}
$imagick = new \Imagick();
$imagick->setResolution(150, 150);
$imagick->readImage($filePath);
$imagick->writeImages($cacheLocation . '/rendered.jpg', true);
}
示例9: 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');
}
}
示例10: save
/**
* {@inheritdoc}
*
* @return ImageInterface
*/
public function save($path = null, array $options = array())
{
$path = null === $path ? $this->imagick->getImageFilename() : $path;
if (null === $path) {
throw new RuntimeException('You can omit save path only if image has been open from a file');
}
try {
$this->prepareOutput($options, $path);
$this->imagick->writeImages($path, true);
} catch (\ImagickException $e) {
throw new RuntimeException('Save operation failed', $e->getCode(), $e);
}
return $this;
}
示例11: processImage
/**
* Processes an image.
*
* @param \Imagick $inputImage
* @return \Imagick The processed image.
*/
public function processImage(\Imagick $inputImage)
{
$totalFrames = 0;
$uniqueFrameDelays = [];
// If the image isn't animated, we don't have to do anything.
if ($inputImage->getIteratorIndex() < 2) {
return $inputImage;
}
$imageCopy = $inputImage->coalesceImages();
// Count frames, and build a set of unique frame delay amounts.
/** @var \Imagick $item */
foreach ($imageCopy as $item) {
$totalFrames++;
$delay = $item->getImageDelay();
if (!isset($uniqueFrameDelays[$delay])) {
$uniqueFrameDelays[$delay] = 0;
}
$uniqueFrameDelays[$delay]++;
}
// If all the frames are the same length, we don't need to do anything.
if (1 === count($uniqueFrameDelays)) {
return $inputImage;
}
// To re-time the animation, we'll need to find the least common
// multiple of all the frame delays.
$frameDelays = array_keys($uniqueFrameDelays);
$newDelay = max(min($frameDelays), gcf_array($frameDelays));
$inputImage = $inputImage->coalesceImages();
$outputImage = new \Imagick();
var_dump(["Input delay", $inputImage->getImageDelay()]);
/** @var \Imagick $frame */
foreach ($inputImage as $frame) {
$outputFrame = clone $frame->getImage();
$frameCount = floor($outputFrame->getImageDelay() / $newDelay);
$outputFrame->setImageDelay($newDelay);
for ($i = 0; $i < $frameCount; $i++) {
$outputImage->addImage($outputFrame);
}
}
// $outputImage = $outputImage->deconstructImages();
$outputImage->setImageFormat('gif');
foreach ($outputImage as $frame) {
var_dump($frame->getImageDelay());
}
var_dump($inputImage->getImageLength());
var_dump($outputImage->getImageLength());
$outputImage->writeImages("output.gif", true);
return $outputImage;
}
示例12: _save
protected function _save($file, $quality)
{
$extension = pathinfo($file, PATHINFO_EXTENSION);
$type = $this->_save_function($extension, $quality);
$this->im->setImageCompressionQuality($quality);
if ($this->im->getNumberImages() > 1 && $extension == "gif") {
$res = $this->im->writeImages($file, true);
} else {
$res = $this->im->writeImage($file);
}
if ($res) {
$this->type = $type;
$this->mime = image_type_to_mime_type($type);
return true;
}
return false;
}
示例13: save
/**
* {@inheritdoc}
*
* @return ImageInterface
*/
public function save($path = null, array $options = array())
{
$path = null === $path ? $this->imagick->getImageFilename() : $path;
if (null === $path) {
throw new RuntimeException('You can omit save path only if image has been open from a file');
}
try {
$this->prepareOutput($options, $path);
/** BEGIN CORE HACK */
// If a specific PNG format is requested, set it
$path = (isset($options['png_format']) ? $options['png_format'] . ':' : '') . $path;
/** END CORE HACK */
$this->imagick->writeImages($path, true);
} catch (\ImagickException $e) {
throw new RuntimeException('Save operation failed', $e->getCode(), $e);
}
return $this;
}
示例14: add_text
$mask = new Imagick($baseUri . 'mask.png');
$overlay = new Imagick($baseUri . 'overlay.png');
add_mask($im, $mask);
add_overlay($im, $overlay);
$mask->destroy();
$overlay->destroy();
$combined->addImage($im);
$im->destroy();
}
#$combined->resetIterator();
#$combined = $combined->appendImages(true);
#$combined->setPage(595,842,0,0);
$combined->setImageFormat('pdf');
#$fp = fopen('/home/gujc/Downloads/test.pdf','wb');
#$combined->writeImagesFile($fp);
$combined->writeImages($baseUri . 'test.pdf', true);
#$combined->destroy();
$reload = new Imagick($baseUri . 'test.pdf');
#$type=$combined->getFormat();
header('Content-type: pdf');
#header('Content-Disposition: attachment;filename="test.pdf"');
echo $reload->getImagesBlob();
function add_text($image, $text, $x = 0, $y = 0, $angle = 0, $style = array())
{
$draw = new ImagickDraw();
if (isset($style['font'])) {
$draw->setFont($style['font']);
}
if (isset($style['font_size'])) {
$draw->setFontSize($style['font_size']);
}
示例15: imagepng
// imagefilter($bm, IMG_FILTER_GRAYSCALE);
// imagecolortransparent($bm, $white);
imagepng(transparent($bm, $new_width, $new_height), $imgdir);
imagedestroy($bm);
} else {
if ($ext === 'eps') {
$im = new Imagick();
$im->setResolution(100, 100);
$im->readImage($imgdir);
$im->setImageFormat("png");
$extln = strlen($ext);
$dir = substr($imgdir, 0, strlen($imgdir) - $extln);
$imgdir = $dir . "png";
// echo $imgdir;
// die();
$im->writeImages($imgdir, true);
$bm = imagecreatefrompng($imgdir);
list($width, $height) = getimagesize($imgdir);
$new_width = $width;
$new_height = $height;
// $white = imagecolorallocate($bm, 255, 255, 255);
// imagefilter($bm, IMG_FILTER_GRAYSCALE);
// imagecolortransparent($bm, $white);
imagepng(transparent($bm, $new_width, $new_height), $imgdir);
imagedestroy($bm);
}
}
}
}
}
}