本文整理匯總了PHP中Imagick::getImageFormat方法的典型用法代碼示例。如果您正苦於以下問題:PHP Imagick::getImageFormat方法的具體用法?PHP Imagick::getImageFormat怎麽用?PHP Imagick::getImageFormat使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Imagick
的用法示例。
在下文中一共展示了Imagick::getImageFormat方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getFormat
/**
* {@inheritdoc}
*/
public function getFormat()
{
$format = $this->imagick->getImageFormat();
if (!in_array($format, static::$supportedFormats)) {
throw new RuntimeException('Unsupported image format');
}
return $format;
}
示例2: update_size
/**
* Updates size properties
*
* @param int $width Image width
* @param int $height Image height
* @param bool $get_format Whether to get image format
*/
protected function update_size($width, $height, $get_format = false)
{
$this->width = $width;
$this->height = $height;
if ($get_format) {
$this->format = strtolower($this->image->getImageFormat());
if ($this->format == 'jpg') {
$this->format = 'jpeg';
}
}
}
示例3: open
/**
* 打開一張圖像
* @param string $imgname 圖像路徑
* @throws \Exception
*/
public function open($imgname)
{
//檢測圖像文件
if (!is_file($imgname)) {
throw new \Exception(_('The image file does not exist'));
}
//銷毀已存在的圖像
empty($this->img) || $this->img->destroy();
//載入圖像
$this->img = new \Imagick(realpath($imgname));
//設置圖像信息
$this->info = array('width' => $this->img->getImageWidth(), 'height' => $this->img->getImageHeight(), 'type' => strtolower($this->img->getImageFormat()), 'mime' => $this->img->getImageMimeType());
}
示例4: load
function load($file_name, $type = '')
{
$this->destroyImage();
$imginfo = @getimagesize($file_name);
if (!$imginfo) {
throw new lmbFileNotFoundException($file_name);
}
$this->img = new Imagick();
$this->img->readImage($file_name);
if (!$this->img instanceof Imagick) {
throw new lmbImageCreateFailedException($file_name);
}
$this->img_type = $this->img->getImageFormat();
}
示例5: createImage
/**
* @param $width
* @param $height
* @return Imagick
*/
protected function createImage($width, $height, $color = "transparent")
{
$newImage = new \Imagick();
$newImage->newimage($width, $height, $color);
$newImage->setImageFormat($this->resource->getImageFormat());
return $newImage;
}
示例6: makeThumb
public function makeThumb($path, $W = NULL, $H = NULL)
{
$image = new Imagick();
$image->readImage($ImgSrc);
// Trasformo in RGB solo se e` il CMYK
if ($image->getImageColorspace() == Imagick::COLORSPACE_CMYK) {
$image->transformImageColorspace(Imagick::COLORSPACE_RGB);
}
$image->profileImage('*', NULL);
$image->stripImage();
$imgWidth = $image->getImageWidth();
$imgHeight = $image->getImageHeight();
if ((!$H || $H == null || $H == 0) && (!$W || $W == null || $W == 0)) {
$W = $imgWidth;
$H = $imgHeight;
} elseif (!$H || $H == null || $H == 0) {
$H = $W * $imgHeight / $imgWidth;
} elseif (!$W || $W == null || $W == 0) {
$W = $H * $imgWidth / $imgHeight;
}
$image->resizeImage($W, $H, Imagick::FILTER_LANCZOS, 1);
/** Scrivo l'immagine */
$image->writeImage($path);
/** IMAGE OUT */
header('X-MHZ-FLY: Nice job!');
header(sprintf('Content-type: image/%s', strtolower($image->getImageFormat())));
echo $image->getImageBlob();
$image->destroy();
die;
}
示例7: _save
/**
*
* @param Imagick $image
* @param string $filename
* @param string $mime_type
* @return array|WP_Error
*/
protected function _save( $image, $filename = null, $mime_type = null ) {
list( $filename, $extension, $mime_type ) = $this->get_output_format( $filename, $mime_type );
if ( ! $filename )
$filename = $this->generate_filename( null, null, $extension );
try {
// Store initial Format
$orig_format = $this->image->getImageFormat();
$this->image->setImageFormat( strtoupper( $this->get_extension( $mime_type ) ) );
$this->make_image( $filename, array( $image, 'writeImage' ), array( $filename ) );
// Reset original Format
$this->image->setImageFormat( $orig_format );
}
catch ( Exception $e ) {
return new WP_Error( 'image_save_error', $e->getMessage(), $filename );
}
// Set correct file permissions
$stat = stat( dirname( $filename ) );
$perms = $stat['mode'] & 0000666; //same permissions as parent folder, strip off the executable bits
@ chmod( $filename, $perms );
/** This filter is documented in wp-includes/class-wp-image-editor-gd.php */
return array(
'path' => $filename,
'file' => wp_basename( apply_filters( 'image_make_intermediate_size', $filename ) ),
'width' => $this->size['width'],
'height' => $this->size['height'],
'mime-type' => $mime_type,
);
}
示例8: thumbnail
/**
* @param $file
* @return string
*/
public function thumbnail($file)
{
$format = '';
$name = md5((new \DateTime())->format('c'));
foreach ($this->sizes as $size) {
$image = new \Imagick($file);
$imageRatio = $image->getImageWidth() / $image->getImageHeight();
$width = $size['width'];
$height = $size['height'];
$customRation = $width / $height;
if ($customRation < $imageRatio) {
$widthThumb = 0;
$heightThumb = $height;
} else {
$widthThumb = $width;
$heightThumb = 0;
}
$image->thumbnailImage($widthThumb, $heightThumb);
$image->cropImage($width, $height, ($image->getImageWidth() - $width) / 2, ($image->getImageHeight() - $height) / 2);
$image->setCompressionQuality(100);
$format = strtolower($image->getImageFormat());
$pp = $this->cachePath . '/' . $size['name'] . "_{$name}." . $format;
$image->writeImage($pp);
}
return "_{$name}." . $format;
}
示例9: watermarkPrint_imagick
private function watermarkPrint_imagick($src, $watermark, $dest_x, $dest_y, $quality, $transparency, $watermarkImgInfo)
{
try {
// Open the original image
$img = new Imagick($src);
// Open the watermark
$watermark = new Imagick($watermark);
// Set transparency
if (strtoupper($watermark->getImageFormat()) !== 'PNG') {
$watermark->setImageOpacity($transparency / 100);
}
// Overlay the watermark on the original image
$img->compositeImage($watermark, imagick::COMPOSITE_OVER, $dest_x, $dest_y);
// Set quality
if (strtoupper($img->getImageFormat()) === 'JPEG') {
$img->setImageCompression(imagick::COMPRESSION_JPEG);
$img->setCompressionQuality($quality);
}
$result = $img->writeImage($src);
$img->clear();
$img->destroy();
$watermark->clear();
$watermark->destroy();
return $result ? true : false;
} catch (Exception $e) {
return false;
}
}
示例10: run
public function run()
{
$faker = Faker::create();
$imgDir = public_path() . DS . 'assets' . DS . 'upload' . DS . 'images';
if (!File::exists($imgDir)) {
File::makeDirectory($imgDir, 0755);
}
File::cleanDirectory($imgDir, true);
foreach (range(1, 500) as $index) {
$dir = $imgDir . DS . $index;
if (!File::exists($dir)) {
File::makeDirectory($dir, 0755);
}
$width = $faker->numberBetween(800, 1024);
$height = $faker->numberBetween(800, 1024);
$orgImg = $faker->image($dir, $width, $height);
chmod($orgImg, 0755);
$img = str_replace($dir . DS, '', $orgImg);
$image = new Imagick($orgImg);
$dpi = $image->getImageResolution();
$dpi = $dpi['x'] > $dpi['y'] ? $dpi['x'] : $dpi['y'];
$size = $image->getImageLength();
$extension = strtolower($image->getImageFormat());
//get 5 most used colors from the image
$color_extractor = new ColorExtractor();
$myfile = $orgImg;
$mime_type = $image->getImageMimeType();
switch ($mime_type) {
case 'image/jpeg':
$palette_obj = $color_extractor->loadJpeg($myfile);
break;
case 'image/png':
$palette_obj = $color_extractor->loadPng($myfile);
break;
case 'image/gif':
$palette_obj = $color_extractor->loadGif($myfile);
break;
}
$main_color = '';
if (is_object($palette_obj)) {
$arr_palette = $palette_obj->extract(5);
if (!empty($arr_palette)) {
$main_color = strtolower($arr_palette[0]);
for ($i = 1; $i < count($arr_palette); $i++) {
$main_color .= ',' . strtolower($arr_palette[$i]);
}
}
}
//update field main_color from images table
$image_obj = VIImage::findorFail((int) $index);
$image_obj->main_color = $main_color;
$image_obj->save();
$id = VIImageDetail::insertGetId(['path' => 'assets/upload/images/' . $index . '/' . $img, 'height' => $height, 'width' => $width, 'ratio' => $width / $height, 'dpi' => $dpi, 'size' => $size, 'extension' => $extension, 'type' => 'main', 'image_id' => $index]);
BackgroundProcess::makeSize($id);
}
}
示例11: setImageFormat
/**
* @param \Imagick $image
* @param string $format
* @return \Imagick
*/
private function setImageFormat($image, $format)
{
if ($image->getImageFormat() !== $format) {
$image->setImageFormat($format);
}
if ($format == 'jpeg') {
$image->setImageCompressionQuality(90);
}
return $image;
}
示例12: inscribeImageIntoCanvas
private function inscribeImageIntoCanvas(\Imagick $image) : \Imagick
{
$dimensions = $image->getImageGeometry();
$x = (int) round(($this->width - $dimensions['width']) / 2);
$y = (int) round(($this->height - $dimensions['height']) / 2);
$canvas = new \Imagick();
$canvas->newImage($this->width, $this->height, $this->backgroundColor, $image->getImageFormat());
$canvas->compositeImage($image, \Imagick::COMPOSITE_OVER, $x, $y);
return $canvas;
}
開發者ID:lizards-and-pumpkins,項目名稱:lib-image-processing-imagick,代碼行數:10,代碼來源:ImageMagickInscribeStrategy.php
示例13: generate
/**
* Generates and dies with an image containing the heading and the text of the error.
*
* @param string $headingText The heading of the error.
* @param string $errorText The text of the error.
*/
public function generate($headingText, $errorText)
{
$draw = new ImagickDraw();
$draw->setFillColor('#777777');
$draw->setFontSize(15);
$draw->setFont('fonts/exo2bold.ttf');
$headingMetrics = $this->canvas->queryFontMetrics($draw, $headingText);
$draw->setFont('fonts/exo2regular.ttf');
$textMetrics = $this->canvas->queryFontMetrics($draw, $errorText);
$this->canvas->newImage(max($textMetrics['textWidth'], $headingMetrics['textWidth']) + 6, $textMetrics['textHeight'] + $headingMetrics['textHeight'] + 6, new ImagickPixel('white'));
$this->canvas->annotateImage($draw, 3, $headingMetrics['textHeight'] * 2, 0, $errorText);
$draw->setFont('fonts/exo2bold.ttf');
$draw->setFillColor('#333333');
$draw->setGravity(Imagick::GRAVITY_NORTH);
$this->canvas->annotateImage($draw, 3, 3, 0, $headingText);
$this->canvas->setImageFormat('png');
header('Content-Type: image/' . $this->canvas->getImageFormat());
header("Cache-Control: max-age=60");
header("Expires: " . gmdate("D, d M Y H:i:s", time() + 60) . " GMT");
die($this->canvas);
}
示例14: getFormat
/**
* @return int
* @throws CM_Exception_Invalid
*/
public function getFormat()
{
$imagickFormat = $this->_imagick->getImageFormat();
switch ($imagickFormat) {
case 'JPEG':
return self::FORMAT_JPEG;
case 'GIF':
return self::FORMAT_GIF;
case 'PNG':
return self::FORMAT_PNG;
default:
throw new CM_Exception_Invalid('Unsupported format `' . $imagickFormat . '`.');
}
}
示例15: copy
/**
* 複製圖片
* @param string $dir
* @param string $fileName
* @return mixed
*/
public function copy($dir = '', $fileName = '')
{
/**
* two ways
* $this->image->writeImage($path);
* file_put_contents($path, $this->image);
*/
$fileName = $fileName ? $fileName : $this->genFileName();
$format = strtolower($this->image->getImageFormat());
$fileName = $fileName . '.' . $format;
$dir = rtrim($dir, '/') . '/';
$realFileName = $dir . $fileName;
//origin file_put_contents
/*
$blobData = $this->image->getImageBlob();
$result = file_put_contents($realFileName,$blobData);
*/
//writeImage
$result = $this->image->writeImage($realFileName);
$storage['fileName'] = $fileName;
$storage['flag'] = $result ? true : false;
return $storage;
}