本文整理匯總了PHP中Imagick::getImagesBlob方法的典型用法代碼示例。如果您正苦於以下問題:PHP Imagick::getImagesBlob方法的具體用法?PHP Imagick::getImagesBlob怎麽用?PHP Imagick::getImagesBlob使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Imagick
的用法示例。
在下文中一共展示了Imagick::getImagesBlob方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getBlob
/**
* @return string
* @throws CM_Exception
*/
public function getBlob()
{
$this->_imagick->setImageCompressionQuality($this->getCompressionQuality());
try {
if ($this->_getAnimationRequired($this->getFormat())) {
$imageBlob = $this->_imagick->getImagesBlob();
} else {
$imageBlob = $this->_imagick->getImageBlob();
}
} catch (ImagickException $e) {
throw new CM_Exception('Cannot get image blob', null, ['originalExceptionMessage' => $e->getMessage()]);
}
return $imageBlob;
}
示例2: post
public function post()
{
if ($this->validate()) {
$image = new PhotoActiveRecord();
$image->userId = Yii::$app->user->identity->id;
$image->name = $this->name . '';
$image->photo = file_get_contents($this->file->tempName);
$image->posted = date('Y-m-d H-i-s');
$imagick = new \Imagick();
$imagick->readImageBlob($image->photo);
$size = $imagick->getImageGeometry();
if ($size['width'] > 800) {
foreach ($imagick as $frame) {
$frame->thumbnailImage(800, 0);
}
}
$image->thumbnail = $imagick->getImagesBlob();
if (!$image->save()) {
return false;
}
$tags = split(',', $this->tags);
foreach ($tags as $item) {
if ($item != '') {
$tag = new TagsActiveRecord();
$tag->photo = $image->id;
$tag->tag = trim($item);
if (!$tag->save()) {
return false;
}
}
}
return true;
}
return false;
}
示例3: 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;
}
示例4: store
public function store($file, $id)
{
$blobOpts = new CreateBlobOptions();
$blobOpts->setContentType($file->getMimeType());
$blobOpts->setCacheControl('max-age=315360000');
try {
$img = new \Imagick($file->getRealPath());
$this->blobRestProxy->createBlockBlob($this->container, $id, $img->getImagesBlob(), $blobOpts);
$img->coalesceImages();
foreach ($img as $frame) {
$frame->thumbnailImage(180, 180);
$frame->setImagePage(180, 180, 0, 0);
}
$this->blobRestProxy->createBlockBlob($this->container, $id . '.t', $img->getImagesBlob(), $blobOpts);
} catch (\Exception $e) {
return $e;
}
return null;
}
示例5: get
/**
* {@inheritdoc}
*/
public function get($format, array $options = array())
{
try {
$options['format'] = $format;
$this->prepareOutput($options);
} catch (\ImagickException $e) {
throw new RuntimeException('Get operation failed', $e->getCode(), $e);
}
return $this->imagick->getImagesBlob();
}
示例6: _render
protected function _render($type, $quality)
{
$type = $this->_save_function($type, $quality);
$this->im->setImageCompressionQuality($quality);
$this->type = $type;
$this->mime = image_type_to_mime_type($type);
if ($this->im->getNumberImages() > 1 && $type == "gif") {
return $this->im->getImagesBlob();
}
return $this->im->getImageBlob();
}
示例7: 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();
}
示例8: getBlob
/**
* @return string
* @throws CM_Exception
*/
public function getBlob()
{
try {
if ($this->_getAnimationRequired($this->getFormat())) {
$imageBlob = $this->_imagick->getImagesBlob();
} else {
$imageBlob = $this->_imagick->getImageBlob();
}
} catch (ImagickException $e) {
throw new CM_Exception('Cannot get image blob: ' . $e->getMessage());
}
return $imageBlob;
}
示例9: register
public function register()
{
if ($this->validate()) {
$user = new User();
$user->username = $this->username;
$user->password = $this->password;
$user->fio = $this->fio;
$user->pol = $this->pol;
$user->birthday = $this->birthday;
$user->country = $this->country;
$user->place = $this->place;
$user->email = $this->email;
$user->registerDate = date('Y-m-d H:i:s');
Yii::trace($this->birthday);
Yii::trace($user->birthday . ' ' . $user->registerDate);
if (!$user->save()) {
return false;
}
if (!Yii::$app->user->login(User::findByUsername($this->username), 0)) {
return false;
}
$photo = new PhotoActiveRecord();
$photo->userId = Yii::$app->user->identity->id;
$photo->photo = file_get_contents($this->photo->tempName);
$imagick = new \Imagick();
$imagick->readImageBlob($photo->photo);
foreach ($imagick as $frame) {
$frame->thumbnailImage(800, 0);
}
$photo->thumbnail = $imagick->getImagesBlob();
$photo->posted = date('Y-m-d H:i:s');
$photo->name = $this->fio;
if (!$photo->save()) {
return false;
}
$user->photo = $photo->id;
$user->save();
return true;
}
return false;
}
示例10: overlay
public function overlay($layer, $x = 0, $y = 0)
{
//$layer_cs = $layer->image->getImageColorspace();
$layer->image->setImageColorspace($this->image->getImageColorspace());
if ($this->multiframe()) {
$this->image = $this->image->coalesceImages();
$width = $this->image->getImageWidth();
$height = $this->image->getImageHeight();
foreach ($this->image as $frame) {
$over = clone $layer->image;
$frame->setImagePage($width, $height, 0, 0);
$frame->compositeImage($over, $this->composition_mode, $x, $y);
}
// It's magic but it work
$this->image->getImagesBlob();
$this->image->deconstructImages();
} else {
$this->image->compositeImage($layer->image, $this->composition_mode, $x, $y);
}
//$layer->image->setImageColorspace($layer_cs);
return $this;
}
示例11: createThumb
public function createThumb($key, $sw = 0, $sh = 0)
{
if (array_key_exists($key, $_FILES) && $_FILES[$key]['size']) {
try {
// イメージ読み込み
$image = new Imagick();
$image->readImageBlob(file_get_contents($_FILES[$key]['tmp_name']));
$iw = $image->getImageWidth();
$ih = $image->getImageHeight();
$uniqid = uniqid('', true);
if ($image->getImageFormat() == 'JPEG') {
$format = 'jpg';
} elseif ($image->getImageFormat() == 'PNG') {
$format = 'png';
} elseif ($image->getImageFormat() == 'GIF') {
$format = 'gif';
} else {
return null;
}
$path_t = APPLICATION_PATH . "/images/thumbnail/" . $uniqid . '.s.' . $format;
$url_t = $this->view->app->base_url . "/images/thumbnail/" . $uniqid . '.s.' . $format;
// リサイズなし
if ($sw == $iw && $sh == $ih) {
// ファイル書き込み
$fh = fopen($path_t, 'wb');
fwrite($fh, $image->getImagesBlob());
fclose($fh);
} elseif ($sw / $iw > $sh / $ih) {
$ww = intval($iw * $sh / $ih);
$hh = intval($ih * $sw / $iw);
$image->scaleImage($sw, $hh);
// 重ね合わせ
$im2 = new Imagick();
$im2->newImage($sw, $sh, "none");
$im2->compositeImage($image, Imagick::COMPOSITE_DEFAULT, 0, intval(($sh - $hh) / 2));
$im2->setImageFormat($format);
// ファイル書き込み
$fh = fopen($path_t, 'wb');
fwrite($fh, $im2->getImagesBlob());
fclose($fh);
} else {
$ww = intval($iw * $sh / $ih);
$hh = intval($ih * $sw / $iw);
$image->scaleImage($ww, $sh);
// 重ね合わせ
$im2 = new Imagick();
$im2->newImage($sw, $sh, "none");
$im2->compositeImage($image, Imagick::COMPOSITE_DEFAULT, intval(($sw - $ww) / 2), 0);
$im2->setImageFormat($format);
// ファイル書き込み
$fh = fopen($path_t, 'wb');
fwrite($fh, $im2->getImagesBlob());
fclose($fh);
}
return array('thumb_url' => $url_t);
} catch (Exception $e) {
return null;
}
} else {
return null;
}
}
示例12: add_text
$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']);
}
if (isset($style['fill_color'])) {
$draw->setFillColor($style['fill_color']);
}
if (isset($style['back_color'])) {
$draw->setTextUnderColor($style['back_color']);
}
示例13: getStream
/**
* {@inheritdoc}
*/
public function getStream()
{
return StreamUtils::create($this->imagick->getImagesBlob());
}
示例14: getOption
/**
* Outputs an image resource as a given type
*
* @param Imagick $im
* @param string $type
* @param string $filename
* @param int $qual
* @return bool
*/
function zp_imageOutput($im, $type, $filename = NULL, $qual = 75)
{
$interlace = getOption('image_interlace');
$qual = max(min($qual, 100), 0);
$im->setImageFormat($type);
switch ($type) {
case 'gif':
$im->setImageCompression(Imagick::COMPRESSION_LZW);
$im->setImageCompressionQuality($qual);
if ($interlace) {
$im->setInterlaceScheme(Imagick::INTERLACE_GIF);
}
break;
case 'jpeg':
case 'jpg':
$im->setImageCompression(Imagick::COMPRESSION_JPEG);
$im->setImageCompressionQuality($qual);
if ($interlace) {
$im->setInterlaceScheme(Imagick::INTERLACE_JPEG);
}
break;
case 'png':
$im->setImageCompression(Imagick::COMPRESSION_ZIP);
$im->setImageCompressionQuality($qual);
if ($interlace) {
$im->setInterlaceScheme(Imagick::INTERLACE_PNG);
}
break;
}
$im->optimizeImageLayers();
if ($filename == NULL) {
header('Content-Type: image/' . $type);
return print $im->getImagesBlob();
}
return $im->writeImages(imgSrcURI($filename), true);
}
示例15: createThumbnail
public function createThumbnail($rawdata, $sw, $sh, $path)
{
// イメージ読み込み
$image = new Imagick();
$image->readImageBlob($rawdata);
$iw = $image->getImageWidth();
$ih = $image->getImageHeight();
// リサイズなし
if ($sw == $iw && $sh == $ih) {
// ファイル書き込み
$fh = fopen($path, 'wb');
fwrite($fh, $image->getImagesBlob());
fclose($fh);
} elseif ($sw / $iw > $sh / $ih) {
$ww = intval($iw * $sh / $ih);
$hh = intval($ih * $sw / $iw);
$image->scaleImage($sw, $hh);
// 重ね合わせ
$im2 = new Imagick();
$im2->newImage($sw, $sh, "none");
$im2->compositeImage($image, Imagick::COMPOSITE_DEFAULT, 0, intval(($sh - $hh) / 2));
//$im2->compositeImage($image, Imagick::COMPOSITE_DEFAULT, 0, 0);
$im2->setImageFormat('jpeg');
// ファイル書き込み
$fh = fopen($path, 'wb');
fwrite($fh, $im2->getImagesBlob());
fclose($fh);
} else {
$ww = intval($iw * $sh / $ih);
$hh = intval($ih * $sw / $iw);
$image->scaleImage($ww, $sh);
// 重ね合わせ
$im2 = new Imagick();
$im2->newImage($sw, $sh, "none");
$im2->compositeImage($image, Imagick::COMPOSITE_DEFAULT, intval(($sw - $ww) / 2), 0);
//$im2->compositeImage($image, Imagick::COMPOSITE_DEFAULT, 0, 0);
$im2->setImageFormat('jpeg');
// ファイル書き込み
$fh = fopen($path, 'wb');
fwrite($fh, $im2->getImagesBlob());
fclose($fh);
}
}