當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Imagick::getImageWidth方法代碼示例

本文整理匯總了PHP中Imagick::getImageWidth方法的典型用法代碼示例。如果您正苦於以下問題:PHP Imagick::getImageWidth方法的具體用法?PHP Imagick::getImageWidth怎麽用?PHP Imagick::getImageWidth使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Imagick的用法示例。


在下文中一共展示了Imagick::getImageWidth方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: pdfAction

 public function pdfAction()
 {
     $model = $this->_processSvg();
     $scale = $this->getRequest()->getPost('print_scale');
     $model->addWhiteFontForPDF();
     $data = $model->normalizeSvgData();
     if ($model->getAdditionalData('order_increment_id')) {
         $filename = 'Order_' . $model->getAdditionalData('order_increment_id') . '_Image.pdf';
     } else {
         $filename = 'Customer_Product_Image.pdf';
     }
     $this->getResponse()->setHttpResponseCode(200)->setHeader('Pragma', 'public', true)->setHeader('Content-type', 'application/pdf', true)->setHeader('Content-Disposition', 'attachment; filename="' . $filename . '"', true);
     $this->getResponse()->clearBody();
     //$this->getResponse()->setBody(str_replace('xlink:','',$data));
     $imagick = new Imagick();
     $imagick->readImageBlob($data);
     if ($scale != 1 && $scale <= 15) {
         $imagick->scaleImage($scale * $imagick->getImageWidth(), $scale * $imagick->getImageHeight());
     }
     $imagick->setImageFormat("pdf");
     /*$imagick->writeImage(MAGENTO_ROOT.'/media/us-map.pdf');scaleImage */
     $this->getResponse()->setBody($imagick);
     $imagick->clear();
     $imagick->destroy();
 }
開發者ID:Eximagen,項目名稱:BulletMagento,代碼行數:25,代碼來源:IndexController.php

示例2: getSize

 /**
  * 獲取圖片尺寸
  * @return array
  */
 public function getSize()
 {
     $wh = [];
     $wh['width'] = $this->image->getImageWidth();
     $wh['height'] = $this->image->getImageHeight();
     return $wh;
 }
開發者ID:apuppy,項目名稱:BlogPrev,代碼行數:11,代碼來源:ImageMagick.php

示例3: thumbImage

 public static function thumbImage($imgPath, $width, $height, $blur = 1, $bestFit = 0, $cropZoom = 1)
 {
     $dir = dirname($imgPath);
     $imagick = new \Imagick(realpath($imgPath));
     if ($imagick->getImageHeight() > $imagick->getImageWidth()) {
         $w = $width;
         $h = 0;
     } else {
         $h = $height;
         $w = 0;
     }
     $imagick->resizeImage($w, $h, $imagick::DISPOSE_UNDEFINED, $blur, $bestFit);
     $cropWidth = $imagick->getImageWidth();
     $cropHeight = $imagick->getImageHeight();
     if ($cropZoom) {
         $imagick->cropImage($width, $height, ($imagick->getImageWidth() - $width) / 2, ($imagick->getImageHeight() - $height) / 2);
     }
     $direct = 'thumbs/';
     $pathToWrite = $dir . "/" . $direct;
     //var_dump($pathToWrite);
     if (!file_exists($pathToWrite)) {
         mkdir($pathToWrite, 0777, true);
     }
     $newImageName = 'thumb_' . basename($imgPath);
     //var_dump($newImageName);
     $imagick->writeImage($pathToWrite . 'thumb_' . basename($imgPath));
     return $pathToWrite . $newImageName;
 }
開發者ID:Snuchycovich,項目名稱:ExifGallery,代碼行數:28,代碼來源:UploadManager.php

示例4: createThumbnailWithImagick

 /**
  * Creates a thumbnail with imagick.
  *
  * @param  File    $fileObject           FileObject to add properties
  * @param  string  $httpPathToMediaDir   Http path to file
  * @param  string  $pathToMediaDirectory Local path to file
  * @param  string  $fileName             Name of the image
  * @param  string  $fileExtension        Fileextension
  * @param  integer $width                Width of thumbnail, if omitted, size will be proportional to height
  * @param  integer $height               Height of thumbnail, if omitted, size will be proportional to width
  *
  * @throws ThumbnailCreationFailedException              If imagick is not supported
  * @throws InvalidArgumentException      If both, height and width are omitted or file format is not supported
  */
 private static function createThumbnailWithImagick(File &$fileObject, $httpPathToMediaDir, $pathToMediaDirectory, $fileName, $fileExtension, $width = null, $height = null)
 {
     if (!extension_loaded('imagick')) {
         throw new ExtensionNotLoadedException('Imagick is not loaded on this system');
     }
     if ($width === null && $height === null) {
         throw new InvalidArgumentException('Either width or height must be provided');
     }
     // create thumbnails with imagick
     $imagick = new \Imagick();
     if (!in_array($fileExtension, $imagick->queryFormats("*"))) {
         throw new ThumbnailCreationFailedException('No thumbnail could be created for the file format');
     }
     // read image into imagick
     $imagick->readImage(sprintf('%s/%s.%s', $pathToMediaDirectory, $fileName, $fileExtension));
     // set size
     $imagick->thumbnailImage($width, $height);
     // null values allowed
     // write image
     $imagick->writeImage(sprintf('%s/%sx%s-thumbnail-%s.%s', $pathToMediaDirectory, $imagick->getImageWidth(), $imagick->getImageHeight(), $fileName, $fileExtension));
     $fileObject->setThumbnailLink(sprintf('%s/%sx%s-thumbnail-%s.%s', $httpPathToMediaDir, $imagick->getImageWidth(), $imagick->getImageHeight(), $fileName, $fileExtension));
     $fileObject->setLocalThumbnailPath(sprintf('%s/%sx%s-thumbnail-%s.%s', $pathToMediaDirectory, $imagick->getImageWidth(), $imagick->getImageHeight(), $fileName, $fileExtension));
     // free up associated resources
     $imagick->destroy();
 }
開發者ID:rmatil,項目名稱:angular-cms,代碼行數:39,代碼來源:ThumbnailHandler.php

示例5: 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;
 }
開發者ID:ahonymous,項目名稱:crop-imagick,代碼行數:30,代碼來源:ImagickService.php

示例6: getAction

 public function getAction($systemIdentifier, Request $request)
 {
     $width = $request->get('width');
     $height = $request->get('height');
     $system = $this->getDoctrine()->getRepository('KoalamonIncidentDashboardBundle:System')->findOneBy(['identifier' => $systemIdentifier, 'project' => $this->getProject()]);
     $webDir = $this->container->getParameter('assetic.write_to');
     if ($system->getImage() == "") {
         $imageName = $webDir . self::DEFAULT_IMAGE;
     } else {
         $imageName = $webDir . ScreenshotCommand::IMAGE_DIR . DIRECTORY_SEPARATOR . $system->getImage();
     }
     $image = new \Imagick($imageName);
     if ($height || $width) {
         if (!$height) {
             $ratio = $width / $image->getImageWidth();
             $height = $image->getImageHeight() * $ratio;
         }
         if (!$width) {
             $ratio = $height / $image->getImageHeight();
             $width = $image->getImageWidth() * $ratio;
         }
         $image->scaleImage($width, $height, true);
     }
     $headers = array('Content-Type' => 'image/png', 'Content-Disposition' => 'inline; filename="' . $imageName . '"');
     return new Response($image->getImageBlob(), 200, $headers);
 }
開發者ID:koalamon,項目名稱:koalamonframeworkbundle,代碼行數:26,代碼來源:DefaultController.php

示例7: draw

 public function draw(OsuSignature $signature)
 {
     parent::draw($signature);
     if ($this->width != -1 || $this->height != -1) {
         $this->image->resizeImage($this->width == -1 ? $this->image->getImageWidth() : $this->width, $this->height == -1 ? $this->image->getImageHeight() : $this->height, 1, $this->filter);
     }
     $signature->getCanvas()->compositeImage($this->image, $this->composite, $this->x, $this->y);
 }
開發者ID:BTCTaras,項目名稱:osusig,代碼行數:8,代碼來源:ComponentImage.php

示例8: testImageWorkingType

 public function testImageWorkingType()
 {
     $file100 = Kwf_Media::getOutput('Kwc_ImageResponsive_MediaOutput_Image_TestComponent', 'root_imageabstract1', 'dh-100-ffa94c');
     $image = new Imagick();
     $image->readimageblob($file100['contents']);
     $this->assertEquals(100, $image->getImageWidth());
     $file200 = Kwf_Media::getOutput('Kwc_ImageResponsive_MediaOutput_Image_TestComponent', 'root_imageabstract1', 'dh-200-ffa94c');
     $image->readimageblob($file200['contents']);
     $this->assertEquals(200, $image->getImageWidth());
 }
開發者ID:xiaoguizhidao,項目名稱:koala-framework,代碼行數:10,代碼來源:ImageTest.php

示例9: loadFile

 /**
  * @see	wcf\system\image\adapter\IImageAdapter::loadFile()
  */
 public function loadFile($file)
 {
     try {
         $this->imagick->readImage($file);
     } catch (\ImagickException $e) {
         throw new SystemException("Image '" . $file . "' is not readable or does not exist.");
     }
     $this->height = $this->imagick->getImageHeight();
     $this->width = $this->imagick->getImageWidth();
 }
開發者ID:ZerGabriel,項目名稱:WCF,代碼行數:13,代碼來源:ImagickImageAdapter.class.php

示例10: _watermark_rand

 /**
  * @return \ImageStorage\Image\Structure\Image
  * @throws \Exception
  */
 private function _watermark_rand()
 {
     if (false === file_exists($this->_watermarkRand->fileName)) {
         throw new \Exception('File ' . $this->_watermarkRand->fileName . ' not exist!');
     }
     $config = $this->_watermarkRand;
     if (false === class_exists('\\Imagick')) {
         return $this->_imageStruct;
     }
     //prepare source in Imagick
     $source = new \Imagick();
     $source->readImageBlob($this->getJpgBlobFromGd($this->_imageStruct->image));
     //prepare watermark
     $watermark = new \Imagick($this->_watermarkRand->fileName);
     $maxWatermarkSize = $source->getImageWidth() * $config->getSize();
     if ($maxWatermarkSize < $config->getMinSize()) {
         $maxWatermarkSize = $config->getMinSize();
     }
     $watermark->thumbnailImage($maxWatermarkSize, $maxWatermarkSize);
     //cache image size
     $imageWidth = $source->getImageWidth();
     $imageHeight = $source->getImageHeight();
     //set max watermarks
     $maxCols = $imageWidth / $config->getMinSize() / 2;
     if ($maxCols < $config->getCols()) {
         $config->setCols(ceil($maxCols));
     }
     $maxRows = $imageHeight / $config->getMinSize() / 2;
     if ($maxRows < $config->getRows()) {
         $config->setRows(ceil($maxRows));
     }
     //step width
     $stepWidth = $imageWidth / $config->getCols();
     $stepHeight = $imageHeight / $config->getRows();
     //put images
     for ($row = 0; $row < $config->getRows(); $row++) {
         for ($col = 0; $col < $config->getCols(); $col++) {
             $x = rand($col * $stepWidth, ($col + 1) * $stepWidth);
             $y = rand($row * $stepHeight, ($row + 1) * $stepHeight);
             //make sure that watermark is in image bound
             if ($x + $maxWatermarkSize > $imageWidth) {
                 $x = $imageWidth - $maxWatermarkSize;
             }
             if ($y + $maxWatermarkSize > $imageHeight) {
                 $y = $imageHeight - $maxWatermarkSize;
             }
             //put watermark to image
             $source->compositeImage($watermark, \Imagick::COMPOSITE_OVER, $x, $y);
         }
     }
     $source->setImageFormat("jpeg");
     $this->_imageStruct->image = imagecreatefromstring($source->getImageBlob());
     return $this->_imageStruct;
 }
開發者ID:umitakkaya,項目名稱:ImageStorage,代碼行數:58,代碼來源:WatermarkRand.php

示例11: 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;
}
開發者ID:atawsports2,項目名稱:Imagick-demos,代碼行數:11,代碼來源:fontEffect.php

示例12: _sharpen

 protected function _sharpen($amount)
 {
     //IM not support $amount under 5 (0.15)
     $amount = $amount < 5 ? 5 : $amount;
     $amount = $amount * 13.0 / 100;
     if ($this->im->sharpenImage(0, $amount)) {
         $this->width = $this->im->getImageWidth();
         $this->height = $this->im->getImageHeight();
         return true;
     }
     return false;
 }
開發者ID:Lazary,項目名稱:webasyst,代碼行數:12,代碼來源:waImageImagick.class.php

示例13: loadDir

function loadDir($path)
{
    if ($handle = opendir($path)) {
        while (false !== ($file = readdir($handle))) {
            if ($file != "." and $file != "..") {
                //skip . and ..
                if (is_file($path . '/' . $file)) {
                    $tmpFile = trim($file);
                    $ext = pathinfo($file, PATHINFO_EXTENSION);
                    $File = pathinfo($file, PATHINFO_FILENAME);
                    $valid_exts = array('jpeg', 'JPEG', 'jpg', 'JPG', 'png', 'PNG', 'gif', 'GIF');
                    $sizes = array('f' => 45, 't' => 92, 's' => 120, 'm' => 225, 'l' => 300);
                    //required sizes in WxH ratio
                    if (in_array($ext, $valid_exts)) {
                        // if file is image then process it!
                        foreach ($sizes as $w => $h) {
                            $image = new Imagick();
                            $image->readImage($path . '/' . $tmpFile);
                            $imgWidth = $image->getImageWidth();
                            $imgHeight = $image->getImageHeight();
                            $image->resizeImage($h, $h, Imagick::FILTER_LANCZOS, 1);
                            // resize from array sizes
                            $fileName .= $File . '_' . $w . '.' . $ext;
                            //create the image filaname
                            $image->writeImage($path . '/' . $fileName);
                            $tempFileName = $path . '/' . $fileName;
                            $arrayfiles[] = $tempFileName;
                            $custWidth = $image->getImageWidth();
                            $custHeight = $image->getImageHeight();
                            echo "[ Original dimension : {$imgWidth} x {$imgHeight} ] [ Custom dimension : {$custWidth} x {$custHeight} ] Output image location: <a href='{$tempFileName}' style='text-decoration:none'> " . $tempFileName . "</a>&nbsp;&nbsp;";
                            echo "<img class='img' src='{$tempFileName}' /></br>";
                            $w = '';
                            $h = '';
                            $fileName = '';
                            $image->clear();
                            $image->destroy();
                        }
                        //end foreach sizes
                    }
                }
                if (is_dir($path . '/' . $file)) {
                    echo '</br> <div style="height:0;width:1200px;border:0;border-bottom:2px;border-style: dashed;border-color: #000000"></div><span style="font-weight:bold; font-size:14px; color:red ">Directory Name: ';
                    echo $path . "/" . $file;
                    echo '</span><div style="height:0;width:1200px;border:0;border-bottom:2px;border-style: dashed;border-color: #000000"></div></br>';
                    loadDir($path . '/' . $file);
                }
            }
        }
        // end while
    }
    // end handle
}
開發者ID:jputz12,項目名稱:OneNow-Vshop,代碼行數:52,代碼來源:index.php

示例14: fxAnalyzeImage

function fxAnalyzeImage(\Imagick $imagick)
{
    $graphWidth = $imagick->getImageWidth();
    $sampleHeight = 20;
    $graphHeight = 128;
    $border = 2;
    $imageIterator = new \ImagickPixelIterator($imagick);
    $reds = [];
    foreach ($imageIterator as $pixels) {
        /* Loop through pixel rows */
        foreach ($pixels as $pixel) {
            /* Loop through the pixels in the row (columns) */
            /** @var $pixel \ImagickPixel */
            $color = $pixel->getColor();
            $reds[] = $color['r'];
        }
        $imageIterator->syncIterator();
        /* Sync the iterator, this is important to do on each iteration */
    }
    $draw = new \ImagickDraw();
    $strokeColor = new \ImagickPixel('red');
    $fillColor = new \ImagickPixel('none');
    $draw->setStrokeColor($strokeColor);
    $draw->setFillColor($fillColor);
    $draw->setStrokeWidth(1);
    $draw->setFontSize(72);
    $draw->setStrokeAntiAlias(true);
    $x = 0;
    $points = [];
    foreach ($reds as $red) {
        $pos = $graphHeight - $red * $graphHeight / 256;
        $points[] = ['x' => $x, 'y' => $pos];
        $x += 1;
    }
    $draw->polyline($points);
    $plot = new \Imagick();
    $plot->newImage($graphWidth, $graphHeight, 'white');
    $plot->drawImage($draw);
    $outputImage = new \Imagick();
    $outputImage->newImage($graphWidth, $graphHeight + $sampleHeight, 'white');
    $outputImage->compositeimage($plot, \Imagick::COMPOSITE_ATOP, 0, 0);
    $imagick->resizeimage($imagick->getImageWidth(), $sampleHeight, \Imagick::FILTER_LANCZOS, 1);
    $outputImage->compositeimage($imagick, \Imagick::COMPOSITE_ATOP, 0, $graphHeight);
    $outputImage->borderimage('black', $border, $border);
    $outputImage->setImageFormat("png");
    header("Content-Type: image/png");
    echo $outputImage;
}
開發者ID:biswajit-paul,項目名稱:gittest,代碼行數:48,代碼來源:functions.php

示例15: addWatermark

 public function addWatermark($image_path)
 {
     try {
         // Open the original image
         $image = new \Imagick();
         $is_success = $image->readImage($image_path);
         if ($is_success === FALSE) {
             throw new WatermarkException("Cannot read uploaded image");
         }
         $watermark = new \Imagick();
         $is_success = $watermark->readImage($this->_WATERMARK_IMAGE_PATH);
         if ($is_success === FALSE) {
             throw new WatermarkException("Cannot read uploaded image");
         }
         $image_width = $image->getImageWidth();
         $image_height = $image->getImageHeight();
         $watermark_width = $watermark->getImageWidth();
         $watermark_height = $watermark->getImageHeight();
         $watermark_pos_x = $image_width - $watermark_width - 20;
         $watermark_pos_y = 20;
         // Overlay the watermark on the original image
         $is_success = $image->compositeImage($watermark, \imagick::COMPOSITE_OVER, $watermark_pos_x, $watermark_pos_y);
         if ($is_success === FALSE) {
             throw new WatermarkException("Cannot save image after watermarked");
         }
         //Write the image
         $image->writeImage($image_path);
     } catch (ImagickException $e) {
         error_log($e->getMessage());
         throw new WatermarkException($e->getMessage(), $e->getCode(), $e);
     }
 }
開發者ID:viggi2004,項目名稱:datacollector-backend,代碼行數:32,代碼來源:Watermark.php


注:本文中的Imagick::getImageWidth方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。