本文整理匯總了PHP中Imagick::addImage方法的典型用法代碼示例。如果您正苦於以下問題:PHP Imagick::addImage方法的具體用法?PHP Imagick::addImage怎麽用?PHP Imagick::addImage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Imagick
的用法示例。
在下文中一共展示了Imagick::addImage方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: offsetSet
/**
* {@inheritdoc}
*/
public function offsetSet($offset, $image)
{
if (!$image instanceof Image) {
throw new InvalidArgumentException('Only an Imagick Image can be used as layer');
}
if (null === $offset) {
$offset = count($this) - 1;
} else {
if (!is_int($offset)) {
throw new InvalidArgumentException('Invalid offset for layer, it must be an integer');
}
if (count($this) < $offset || 0 > $offset) {
throw new OutOfBoundsException(sprintf('Invalid offset for layer, it must be a value between 0 and %d, %d given', count($this), $offset));
}
if (isset($this[$offset])) {
unset($this[$offset]);
$offset = $offset - 1;
}
}
$frame = $image->getImagick();
try {
if (count($this) > 0) {
$this->resource->setIteratorIndex($offset);
}
$this->resource->addImage($frame);
} catch (\ImagickException $e) {
throw new RuntimeException('Unable to set the layer', $e->getCode(), $e);
}
$this->layers = array();
}
示例2: removeAnimation
/**
* Turns object into one frame Imagick object
* by removing all frames except first
*
* @param Imagick $object
* @return Imagick
*/
private function removeAnimation(\Imagick $object)
{
$imagick = new \Imagick();
foreach ($object as $frame) {
$imagick->addImage($frame->getImage());
break;
}
$object->destroy();
return $imagick;
}
示例3: createThumb
public function createThumb()
{
// $imagick = new \Imagick();
$output = new \Imagick();
$imagick->setIteratorIndex(1);
$output->addImage($imagick->getimage());
// $imagick->setIteratorIndex(2);
// $output->addImage($imagick->getimage());
$merged = @$output->flattenimages();
$merged->setImageFormat('jpg');
$merged->writeImage('test.jpg');
}
示例4: 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();
}
示例5: 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;
}
示例6: example2
public function example2()
{
$graph = new \Imagick();
$graph->newPseudoImage(256, 256, "xc:pink");
$imagick = new \Imagick();
$imagick->newPseudoImage(256, 256, 'gradient:black-white');
$arguments = array(9, -90);
$imagick->functionImage(\Imagick::FUNCTION_SINUSOID, $arguments);
$graph->addImage($imagick);
$fx = 'colorInt=int(256 * v.p{0,j}.lightness); pos=int(i); (int(pos) >= colorInt && int(pos) <= colorInt)';
$fxImage = $graph->fxImage($fx);
// fxAnalyzeImage($imagick);
header("Content-Type: image/png");
$fxImage->setimageformat('png');
echo $fxImage->getImageBlob();
}
示例7: 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;
}
示例8: Imagick
<?php
$combined = null;
$images = ['../../../imagick/images/Biter_500.jpg', '../../../imagick/images/Source1.png'];
foreach ($images as $image) {
/** @var $combined \Imagick */
if ($combined == null) {
$combined = new Imagick(realpath($image));
} else {
$card = new Imagick(realpath($image));
//get single card
$combined->addImage($card);
}
}
$combined->setImageFormat("pdf");
$combined->writeImages('./card.pdf', true);
示例9: foreach
/**
* Resamples an image to a new copy
*
* @param Imagick $dst_image
* @param Imagick $src_image
* @param int $dst_x
* @param int $dst_y
* @param int $src_x
* @param int $src_y
* @param int $dst_w
* @param int $dst_h
* @param int $src_w
* @param int $src_h
* @return bool
*/
function zp_resampleImage($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h)
{
foreach ($src_image->getImageProfiles() as $name => $profile) {
$dst_image->profileImage($name, $profile);
}
$result = true;
$src_image = $src_image->coalesceImages();
foreach ($src_image as $frame) {
$frame->cropImage($src_w, $src_h, $src_x, $src_y);
$frame->setImagePage(0, 0, 0, 0);
}
$src_image = $src_image->coalesceImages();
foreach ($src_image as $frame) {
$frame->resizeImage($dst_w, $dst_h, Imagick::FILTER_LANCZOS, 1);
$dst_image->setImageDelay($frame->getImageDelay());
$result &= $dst_image->compositeImage($frame, Imagick::COMPOSITE_OVER, $dst_x, $dst_y);
if ($dst_image->getNumberImages() < $src_image->getNumberImages()) {
$result &= $dst_image->addImage(zp_createImage($dst_image->getImageWidth(), $dst_image->getImageHeight()));
}
if (!$result) {
break;
}
}
return $result;
}
示例10: Imagick
if (!in_array($tileNumber, $frames)) {
continue;
}
$path = $dir . '/' . $filename;
$originalImage = new Imagick($path);
$resultImage->addimage($originalImage);
$originalImage->clear();
$originalImage->destroy();
}
$resultImages[$direction] = $resultImage;
}
$image = new Imagick();
foreach ($resultImages as $resultImage) {
/** @var Imagick $resultImage */
$resultImage->resetIterator();
$sprite = $resultImage->appendImages(false);
$resultImage->clear();
$resultImage->destroy();
$sprite->setImageFormat('png');
$image->addImage($sprite);
$sprites[] = $sprite;
}
$image->resetIterator();
$response = $image->appendImages(true);
$image->clear();
$image->destroy();
$response->setImageFormat('png');
$response->writeImage(__DIR__ . '/' . $argv[1] . '.png');
$response->clear();
$response->destroy();
echo 'All files were processed', PHP_EOL;
示例11: imgSquareFit
/**
* Put image to square
*
* @param string $path image file
* @param int $width square width
* @param int $height square height
* @param int|string $align reserved
* @param int|string $valign reserved
* @param string $bgcolor square background color in #rrggbb format
* @param string $destformat image destination format
* @param int $jpgQuality JEPG quality (1-100)
* @return false|string
* @author Dmitry (dio) Levashov
* @author Alexey Sukhotin
*/
protected function imgSquareFit($path, $width, $height, $align = 'center', $valign = 'middle', $bgcolor = '#0000ff', $destformat = null, $jpgQuality = null)
{
if (($s = getimagesize($path)) == false) {
return false;
}
$result = false;
/* Coordinates for image over square aligning */
$y = ceil(abs($height - $s[1]) / 2);
$x = ceil(abs($width - $s[0]) / 2);
if (!$jpgQuality) {
$jpgQuality = $this->options['jpgQuality'];
}
elFinder::extendTimeLimit(300);
switch ($this->imgLib) {
case 'imagick':
try {
$img = new imagick($path);
} catch (Exception $e) {
return false;
}
if ($bgcolor === 'transparent') {
$bgcolor = 'rgba(255, 255, 255, 0.0)';
}
$ani = $img->getNumberImages() > 1;
if ($ani && is_null($destformat)) {
$img1 = new Imagick();
$img1->setFormat('gif');
$img = $img->coalesceImages();
do {
$gif = new Imagick();
$gif->newImage($width, $height, new ImagickPixel($bgcolor));
$gif->setImageColorspace($img->getImageColorspace());
$gif->setImageFormat('gif');
$gif->compositeImage($img, imagick::COMPOSITE_OVER, $x, $y);
$gif->setImageDelay($img->getImageDelay());
$gif->setImageIterations($img->getImageIterations());
$img1->addImage($gif);
$gif->clear();
} while ($img->nextImage());
$img1 = $img1->optimizeImageLayers();
$result = $img1->writeImages($path, true);
} else {
if ($ani) {
$img->setFirstIterator();
}
$img1 = new Imagick();
$img1->newImage($width, $height, new ImagickPixel($bgcolor));
$img1->setImageColorspace($img->getImageColorspace());
$img1->compositeImage($img, imagick::COMPOSITE_OVER, $x, $y);
$result = $this->imagickImage($img1, $path, $destformat, $jpgQuality);
}
$img1->clear();
$img->clear();
return $result ? $path : false;
break;
case 'convert':
extract($this->imageMagickConvertPrepare($path, $destformat, $jpgQuality, $s));
if ($bgcolor === 'transparent') {
$bgcolor = 'rgba(255, 255, 255, 0.0)';
}
$cmd = sprintf('convert -size %dx%d "xc:%s" png:- | convert%s%s png:- %s -geometry +%d+%d -compose over -composite%s %s', $width, $height, $bgcolor, $coalesce, $jpgQuality, $quotedPath, $x, $y, $deconstruct, $quotedDstPath);
$result = false;
if ($this->procExec($cmd) === 0) {
$result = true;
}
return $result ? $path : false;
break;
case 'gd':
$img = $this->gdImageCreate($path, $s['mime']);
if ($img && false != ($tmp = imagecreatetruecolor($width, $height))) {
$this->gdImageBackground($tmp, $bgcolor);
if ($bgcolor === 'transparent' && ($destformat === 'png' || $s[2] === IMAGETYPE_PNG)) {
$bgNum = imagecolorallocatealpha($tmp, 255, 255, 255, 127);
imagefill($tmp, 0, 0, $bgNum);
}
if (!imagecopy($tmp, $img, $x, $y, 0, 0, $s[0], $s[1])) {
return false;
}
$result = $this->gdImage($tmp, $path, $destformat, $s['mime'], $jpgQuality);
imagedestroy($img);
imagedestroy($tmp);
return $result ? $path : false;
}
break;
}
//.........這裏部分代碼省略.........
示例12: thumb
public function thumb($width, $height, $type = THINKIMAGE_THUMB_SCALE)
{
if (empty($this->img)) {
throw new Exception("沒有可以被縮略的圖像資源");
}
$w = $this->info["width"];
$h = $this->info["height"];
switch ($type) {
case THINKIMAGE_THUMB_SCALE:
if ($w < $width && $h < $height) {
return NULL;
}
$scale = min($width / $w, $height / $h);
$x = $y = 0;
$width = $w * $scale;
$height = $h * $scale;
break;
case THINKIMAGE_THUMB_CENTER:
$scale = max($width / $w, $height / $h);
$w = $width / $scale;
$h = $height / $scale;
$x = ($this->info["width"] - $w) / 2;
$y = ($this->info["height"] - $h) / 2;
break;
case THINKIMAGE_THUMB_NORTHWEST:
$scale = max($width / $w, $height / $h);
$x = $y = 0;
$w = $width / $scale;
$h = $height / $scale;
break;
case THINKIMAGE_THUMB_SOUTHEAST:
$scale = max($width / $w, $height / $h);
$w = $width / $scale;
$h = $height / $scale;
$x = $this->info["width"] - $w;
$y = $this->info["height"] - $h;
break;
case THINKIMAGE_THUMB_FILLED:
if ($w < $width && $h < $height) {
$scale = 1;
} else {
$scale = min($width / $w, $height / $h);
}
$neww = $w * $scale;
$newh = $h * $scale;
$posx = ($width - $w * $scale) / 2;
$posy = ($height - $h * $scale) / 2;
$newimg = new Imagick();
$newimg->newImage($width, $height, "white", $this->info["type"]);
if ("gif" == $this->info["type"]) {
$imgs = $this->img->coalesceImages();
$img = new Imagick();
$this->img->destroy();
do {
$image = $this->_fill($newimg, $posx, $posy, $neww, $newh, $imgs);
$img->addImage($image);
$img->setImageDelay($imgs->getImageDelay());
$img->setImagePage($width, $height, 0, 0);
$image->destroy();
} while ($imgs->nextImage());
$this->img->destroy();
$this->img = $img->deconstructImages();
$imgs->destroy();
$img->destroy();
} else {
$img = $this->_fill($newimg, $posx, $posy, $neww, $newh);
$this->img->destroy();
$this->img = $img;
}
$this->info["width"] = $width;
$this->info["height"] = $height;
return NULL;
case THINKIMAGE_THUMB_FIXED:
$x = $y = 0;
break;
default:
throw new Exception("不支持的縮略圖裁剪類型");
}
$this->crop($w, $h, $x, $y, $width, $height);
}
示例13: add_watermark
public function add_watermark($path, $x = 0, $y = 0)
{
$watermark = new Imagick($path);
$draw = new ImagickDraw();
$draw->composite($watermark->getImageCompose(), $x, $y, $watermark->getImageWidth(), $watermark->getimageheight(), $watermark);
if ($this->type == 'gif') {
$image = $this->image;
$canvas = new Imagick();
$images = $image->coalesceImages();
foreach ($image as $frame) {
$img = new Imagick();
$img->readImageBlob($frame);
$img->drawImage($draw);
$canvas->addImage($img);
$canvas->setImageDelay($img->getImageDelay());
}
$image->destroy();
$this->image = $canvas;
} else {
$this->image->drawImage($draw);
}
}
示例14: ImagickResizeImage
function ImagickResizeImage($srcFile, $destFile, $new_w, $new_h, $zhenshu = false)
{
if ($new_w <= 0 || $new_h <= 0 || !file_exists($srcFile)) {
return false;
}
$src = new Imagick($srcFile);
$image_format = strtolower($src->getImageFormat());
if ($image_format != 'jpeg' && $image_format != 'gif' && $image_format != 'png' && $image_format != 'jpg' && $image_format != 'bmp') {
return false;
}
//如果是 jpg jpeg
if ($image_format != 'gif') {
$dest = $src;
$dest->thumbnailImage($new_w, $new_h, true);
$dest->writeImage($destFile);
$dest->clear();
//gif需要以幀一幀的處理
} else {
$dest = new Imagick();
$color_transparent = new ImagickPixel("transparent");
//透明色
$gif_i = 1;
foreach ($src as $img) {
$page = $img->getImagePage();
$tmp = new Imagick();
$tmp->newImage($page['width'], $page['height'], $color_transparent, 'gif');
$tmp->compositeImage($img, Imagick::COMPOSITE_OVER, $page['x'], $page['y']);
$tmp->thumbnailImage($new_w, $new_h, true);
$dest->addImage($tmp);
$dest->setImagePage($tmp->getImageWidth(), $tmp->getImageHeight(), 0, 0);
$dest->setImageDelay($img->getImageDelay());
$dest->setImageDispose($img->getImageDispose());
if ($zhenshu > 0) {
if ($zhenshu <= $gif_i) {
break;
}
$gif_i++;
}
}
$dest->coalesceImages();
$dest->writeImages($destFile, true);
$dest->clear();
}
}
示例15: GetView
function GetView()
{
global $TMP_PATH;
$tmp_file = ADEI::GetTmpFile();
$servername = "localhost";
$username = "cube";
$password = "cube";
$dbname = "HDCP10";
$width = 800;
$height = 600;
$window = "1365832800-1365854400";
$interval = explode("-", $this->window);
$total_seconds = $interval[1] - $interval[0];
$start = $interval[0] * 1000000;
$end = $interval[1] * 1000000;
$im = new Imagick();
$draw2 = new ImagickDraw();
$draw2->setStrokeColor("#808080");
$draw2->setStrokeWidth(1);
$draw2->setFontSize(72);
$draw2->line(700, 240, 800, 240);
$ystroke = new Imagick();
$ystroke->newImage(800, 480, "white");
$ystroke->setImageFormat("png");
$ystroke->drawImage($draw2);
$im->addImage($ystroke);
$draw = new ImagickDraw();
$draw->setStrokeColor("#808080");
$draw->setStrokeWidth(100);
$draw->setFontSize(72);
$draw->line(100, 0, 100, 480);
$yaxis = new Imagick();
$yaxis->newImage(100, 480, "white");
$yaxis->setImageFormat("png");
$yaxis->drawImage($draw);
$im->addImage($yaxis);
try {
$conn = new PDO("mysql:host={$servername};dbname={$dbname}", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "SELECT count(*) FROM Profiles_060_WTH_STATIC_EL90_Images_1 WHERE P_id = 8";
$stmt = $conn->query($sql);
$row = $stmt->fetch();
$total = $row[0];
$sql = "SELECT img_id, image FROM Profiles_060_WTH_STATIC_EL90_Images_1 WHERE P_id = 8 ORDER BY img_id ASC";
$stmt = $conn->query($sql);
while ($row = $stmt->fetchObject()) {
if (is_null($row->image)) {
$im->newImage(7, 480, "white");
continue;
}
$im->readimageblob($row->image);
}
} catch (PDOException $e) {
//echo "Connection failed: " . $e->getMessage();
}
/* Create new imagick object */
//$im = new Imagick();
/* create red, green and blue images */
//$im->newImage(100, 50, "red");
//$im->newImage(100, 50, "green");
//$im->newImage(100, 50, "blue");
/* Append the images into one */
$im->resetIterator();
$combined = $im->appendImages(false);
/* Output the image */
$combined->setImageFormat("png");
/*
Having to do alot of resizing, i needed to know the speeds of the different resize filters.
This was how long it took to resize a 5906x5906 JPEG image to 1181x1181.
FILTER_POINT took: 0.334532976151 seconds
FILTER_BOX took: 0.777871131897 seconds
FILTER_TRIANGLE took: 1.3695909977 seconds
FILTER_HERMITE took: 1.35866093636 seconds
FILTER_HANNING took: 4.88722896576 seconds
FILTER_HAMMING took: 4.88665103912 seconds
FILTER_BLACKMAN took: 4.89026689529 seconds
FILTER_GAUSSIAN took: 1.93553304672 seconds
FILTER_QUADRATIC took: 1.93322920799 seconds
FILTER_CUBIC took: 2.58396601677 seconds
FILTER_CATROM took: 2.58508896828 seconds
FILTER_MITCHELL took: 2.58368492126 seconds
FILTER_LANCZOS took: 3.74232912064 seconds
FILTER_BESSEL took: 4.03305602074 seconds
FILTER_SINC took: 4.90098690987 seconds
*/
$combined->resizeImage(1200, 600, Imagick::FILTER_LANCZOS, 1);
#$draw3 = new ImagickDraw();
#$draw3->setStrokeColor("black");
//$draw3->setFillColor($fillColor);
#$draw3->setStrokeWidth(0.1);
#$draw3->setFontSize(8);
#$combined->annotateImage($draw3, 0, 300, 0, "500");
file_put_contents("{$TMP_PATH}/{$tmp_file}", $combined);
return array("img" => array("id" => $tmp_file));
}