当前位置: 首页>>代码示例>>PHP>>正文


PHP imagick::writeImage方法代码示例

本文整理汇总了PHP中imagick::writeImage方法的典型用法代码示例。如果您正苦于以下问题:PHP imagick::writeImage方法的具体用法?PHP imagick::writeImage怎么用?PHP imagick::writeImage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在imagick的用法示例。


在下文中一共展示了imagick::writeImage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: mkdir

 function cdm_thumbPdf($pdf)
 {
     if (class_exists('imagick')) {
         $upload_dir = wp_upload_dir();
         $tmp_folder = $upload_dir['basedir'] . '/imageMagick_tmp/';
         if (!is_dir($tmp_folder)) {
             mkdir($tmp_folder, 0777);
         }
         $tmp = $tmp_folder;
         $format = "png";
         $source = $pdf;
         $dest = "" . $pdf . "_big.{$format}";
         $dest2 = "" . $pdf . "_small.{$format}";
         // read page 1
         $im = new imagick('' . $source . '[0]');
         // convert to jpg
         $im->setImageColorspace(255);
         $im->setImageFormat($format);
         //resize
         $im->resizeImage(650, 650, imagick::FILTER_LANCZOS, 1);
         //write image on server
         $im->writeImage($dest);
         //resize
         $im->resizeImage(250, 250, imagick::FILTER_LANCZOS, 1);
         //write image on server
         $im->writeImage($dest2);
         $im->clear();
         $im->destroy();
     } else {
         echo 'php-image-magick not installed. Please disable the pdf thumbnail options or install the php extention correctly.';
         exit;
     }
 }
开发者ID:beafus,项目名称:Living-Meki-Platform,代码行数:33,代码来源:functions.php

示例2: processPdf

 public function processPdf($fileNames)
 {
     $mpdf = Yii::app()->ePdf->mpdf();
     $mpdf->SetImportUse();
     $pagecount = $mpdf->SetSourceFile('../' . $fileNames['pdf']);
     if ($pagecount > 3) {
         for ($i = 1; $i <= 3; $i++) {
             if ($i != 1) {
                 $mpdf->AddPage();
             }
             $import_page = $mpdf->ImportPage($i);
             // add last 3 page
             $mpdf->UseTemplate($import_page);
         }
     } else {
         $tplId = $mpdf->ImportPage($pagecount);
         $mpdf->UseTemplate($tplId);
     }
     $mpdf->Output('../' . Extensions::FILE_PDF_PREVIEW_PATH . $fileNames['pdfPreview'], 'F');
     $im = new imagick();
     $im->readimage('/home/notesgen/public_html/' . Extensions::FILE_PDF_PREVIEW_PATH . $fileNames['pdfPreview']);
     $im->setImageCompressionQuality(0);
     $im->setImageFormat('jpeg');
     $im->writeImage('../' . Extensions::FILE_IMAGE_PATH . $fileNames['image']);
     $im->setImageCompressionQuality(80);
     $im->writeImage('../' . Extensions::FILE_IMAGE_PATH_APP . $fileNames['image']);
     $im->clear();
     $im->destroy();
 }
开发者ID:kuldeepro,项目名称:notesgen,代码行数:29,代码来源:CronController.php

示例3: makethumb

function makethumb($srcFile, $dstFile, $dstW, $dstH, $imwf = false)
{
    $im = new imagick($srcFile);
    $source_w = $im->getImageWidth();
    $source_h = $im->getImageHeight();
    if ($dstW === 0 && $dstH === 0) {
        $dstW = $source_w;
        $dstH = $source_h;
    } else {
        // 取得縮在此範圍內的比例
        $percent = getResizePercent($source_w, $source_h, $dstW, $dstH);
        $dstW = $source_w * $percent;
        $dstH = $source_h * $percent;
    }
    $im->thumbnailImage($dstW, $dstH);
    $im->writeImage($dstFile);
    $watermarkFile = './logo.png';
    if ($imwf && is_file($watermarkFile) && is_file($dstFile)) {
        $image = new imagick($dstFile);
        $watermark = new imagick($watermarkFile);
        $iWidth = $image->getImageWidth();
        $iHeight = $image->getImageHeight();
        $wWidth = $watermark->getImageWidth();
        $wHeight = $watermark->getImageHeight();
        if ($iHeight < $wHeight || $iWidth < $wWidth) {
            $watermark->scaleImage($iWidth, $iHeight);
            $wWidth = $watermark->getImageWidth();
            $wHeight = $watermark->getImageHeight();
        }
        $x = ($iWidth - $wWidth) / 2;
        $y = ($iHeight - $wHeight) / 2;
        $image->compositeImage($watermark, imagick::COMPOSITE_OVER, $x, $y);
        $image->writeImage($dstFile);
    }
}
开发者ID:FantasticThought,项目名称:tfsda,代码行数:35,代码来源:image_conver.php

示例4: createThumb

 private function createThumb($filePath, $fileName)
 {
     if (!extension_loaded('imagick')) {
         $errorMessage = "Error: 874";
         $this->error($errorMessage);
     }
     try {
         $fileNameWithoutExt = $fileName;
         $imagePreview = new imagick($this->uploadsDir . $fileName);
         $imagePreview->scaleImage(300, 0);
         $imagePreview->writeImage($this->thumbDir . $fileNameWithoutExt);
     } catch (ImagickException $e) {
         $errorMessage = "Error: 3435";
         $this->error($errorMessage);
     }
     return $fileNameWithoutExt;
 }
开发者ID:mawilliamson,项目名称:wordpress,代码行数:17,代码来源:file_uploader.php

示例5: resizeCropImg

 private function resizeCropImg($pFolder, $pImg, $pW, $pH)
 {
     $im = new imagick();
     $im->readImage($pFolder . $pImg);
     $image = new stdClass();
     $image->dimensions = $im->getImageGeometry();
     $image->w = $image->dimensions['width'];
     $image->h = $image->dimensions['height'];
     $image->ratio = $image->w / $image->h;
     if ($image->w / $pW < $image->h / $pH) {
         $h = ceil($pH * $image->w / $pW);
         $y = ($image->h - $pH * $image->w / $pW) / 2;
         $im->cropImage($image->w, $h, 0, $y);
     } else {
         $w = ceil($pW * $image->h / $pH);
         $x = ($image->w - $pW * $image->h / $pH) / 2;
         $im->cropImage($w, $image->h, $x, 0);
     }
     $im->ThumbnailImage($pW, $pH, true);
     if ($img->type === "PNG") {
         $im->setImageCompressionQuality(55);
         $im->setImageFormat('png');
     } elseif ($img->type === "JPG" || $img->type === "JPEG") {
         $im->setCompressionQuality(100);
         $im->setImageFormat("jpg");
     }
     $im->writeImage($this->ad->url->folder . '/assets/' . $pImg);
     $im->destroy();
 }
开发者ID:arnolali,项目名称:incontournables-du-voyage,代码行数:29,代码来源:Ad.php

示例6: createTmb

 /**
  * Create thumnbnail and return it's URL on success
  *
  * @param  string $path file path
  * @param $stat
  * @return false|string
  * @internal param string $mime file mime type
  * @author Dmitry (dio) Levashov
  */
 protected function createTmb($path, $stat)
 {
     if (!$stat || !$this->canCreateTmb($path, $stat)) {
         return false;
     }
     $name = $this->tmbname($stat);
     $tmb = $this->tmbPath . DIRECTORY_SEPARATOR . $name;
     $maxlength = -1;
     $imgConverter = null;
     // check imgConverter
     $mime = strtolower($stat['mime']);
     list($type) = explode('/', $mime);
     if (isset($this->imgConverter[$mime])) {
         $imgConverter = $this->imgConverter[$mime]['func'];
         if (!empty($this->imgConverter[$mime]['maxlen'])) {
             $maxlength = intval($this->imgConverter[$mime]['maxlen']);
         }
     } else {
         if (isset($this->imgConverter[$type])) {
             $imgConverter = $this->imgConverter[$type]['func'];
             if (!empty($this->imgConverter[$type]['maxlen'])) {
                 $maxlength = intval($this->imgConverter[$type]['maxlen']);
             }
         }
     }
     if ($imgConverter && !is_callable($imgConverter)) {
         return false;
     }
     // copy image into tmbPath so some drivers does not store files on local fs
     if (($src = $this->fopenCE($path, 'rb')) == false) {
         return false;
     }
     if (($trg = fopen($tmb, 'wb')) == false) {
         $this->fcloseCE($src, $path);
         return false;
     }
     stream_copy_to_stream($src, $trg, $maxlength);
     $this->fcloseCE($src, $path);
     fclose($trg);
     // call imgConverter
     if ($imgConverter) {
         if (!call_user_func_array($imgConverter, array($tmb, $stat, $this))) {
             file_exists($tmb) && unlink($tmb);
             return false;
         }
     }
     $result = false;
     $tmbSize = $this->tmbSize;
     if ($this->imgLib === 'imagick') {
         try {
             $imagickTest = new imagick($tmb);
             $imagickTest->clear();
             $imagickTest = true;
         } catch (Exception $e) {
             $imagickTest = false;
         }
     }
     if ($this->imgLib === 'imagick' && !$imagickTest || ($s = getimagesize($tmb)) === false) {
         if ($this->imgLib === 'imagick') {
             $bgcolor = $this->options['tmbBgColor'];
             if ($bgcolor === 'transparent') {
                 $bgcolor = 'rgba(255, 255, 255, 0.0)';
             }
             try {
                 $imagick = new imagick();
                 $imagick->setBackgroundColor(new ImagickPixel($bgcolor));
                 $imagick->readImage($this->getExtentionByMime($stat['mime'], ':') . $tmb);
                 $imagick->setImageFormat('png');
                 $imagick->writeImage($tmb);
                 $imagick->clear();
                 if (($s = getimagesize($tmb)) !== false) {
                     $result = true;
                 }
             } catch (Exception $e) {
             }
         }
         if (!$result) {
             file_exists($tmb) && unlink($tmb);
             return false;
         }
         $result = false;
     }
     /* If image smaller or equal thumbnail size - just fitting to thumbnail square */
     if ($s[0] <= $tmbSize && $s[1] <= $tmbSize) {
         $result = $this->imgSquareFit($tmb, $tmbSize, $tmbSize, 'center', 'middle', $this->options['tmbBgColor'], 'png');
     } else {
         if ($this->options['tmbCrop']) {
             $result = $tmb;
             /* Resize and crop if image bigger than thumbnail */
             if (!($s[0] > $tmbSize && $s[1] <= $tmbSize || $s[0] <= $tmbSize && $s[1] > $tmbSize) || $s[0] > $tmbSize && $s[1] > $tmbSize) {
                 $result = $this->imgResize($tmb, $tmbSize, $tmbSize, true, false, 'png');
//.........这里部分代码省略.........
开发者ID:bigbrush,项目名称:yii2-big,代码行数:101,代码来源:elFinderVolumeDriver.class.php

示例7: getPdfFromImages

 /**
  * Generate pdf, preview pdf from images uploaded by user.
  *
  * @param array $images
  *
  * @return array
  *
  * @author Kuldeep Dangi <kuldeep.dangi@yiifrmae.com>
  */
 public function getPdfFromImages($images)
 {
     $fileUploadAbsolutePath = Yii::app()->params['FILE_SERVER_IMAGE_PATH'] . self::FILE_UPLOAD_PATH;
     $pdfUploadAbsolutePath = Yii::app()->params['FILE_SERVER_IMAGE_PATH'] . self::FILE_CONVERT_PATH;
     $upload_file = array();
     $html = $previewHtml = '';
     $randomNumber = MD5($this->getRandomNumber());
     $savedFileNames = array('image' => $randomNumber . '.jpg', 'imagepdf' => $randomNumber . '.pdf.pdf', 'pdf' => $randomNumber . '.pdf');
     $imagesCount = count($images);
     $imageCounterCount = 1;
     foreach ($images as $image) {
         if ($imagesCount > 3 && $imageCounterCount < 4) {
             $previewHtml .= '<img src="../' . self::FILE_UPLOAD_PATH . $image . '"/>';
         } elseif ($imagesCount < 4 && $imageCounterCount == $imagesCount) {
             $previewHtml .= '<img src="../' . self::FILE_UPLOAD_PATH . $image . '"/>';
         }
         $html .= '<img src="../' . self::FILE_UPLOAD_PATH . $image . '"/>';
         $imageCounterCount++;
     }
     $mpdf = Yii::app()->ePdf->mpdf();
     $mpdf->debug = true;
     $mpdf->WriteHTML($html);
     $mpdf->Output('../' . self::FILE_CONVERT_PATH . $savedFileNames['pdf'], 'F');
     $mpdf1 = Yii::app()->ePdf->mpdf();
     $mpdf1->debug = true;
     $mpdf1->WriteHTML($previewHtml);
     $mpdf1->Output('../' . self::FILE_PDF_PREVIEW_PATH . $savedFileNames['imagepdf'], 'F');
     $im = new imagick();
     $im->readimage('/home/notesgen/public_html/' . self::FILE_PDF_PREVIEW_PATH . $savedFileNames['imagepdf']);
     $im->setImageCompressionQuality(0);
     $im->setImageFormat('jpeg');
     $im->writeImage('../' . self::FILE_IMAGE_PATH . $savedFileNames['image']);
     $im->setImageCompressionQuality(80);
     $im->writeImage('../' . self::FILE_IMAGE_PATH_APP . $savedFileNames['image']);
     $im->clear();
     $im->destroy();
     return $savedFileNames;
 }
开发者ID:kuldeepro,项目名称:notesgen,代码行数:47,代码来源:Extensions.php

示例8: wordwrap

/* Font properties */
$draw3->setFont($signatureFont);
$draw3->setFontSize($signatureSize);
$draw3->setFontWeight(400);
// change wordwrap depending on font size
switch ($signatureSize) {
    case 20:
        $signatureWordwrap = 24;
        break;
    case 22:
        $signatureWordwrap = 23;
        break;
    case 24:
        $signatureWordwrap = 21;
        break;
    case 26:
        $signatureWordwrap = 19;
        break;
    case 28:
        $signatureWordwrap = 17;
        break;
    case 30:
        $signatureWordwrap = 16;
        break;
}
$fixedCardSignature = wordwrap($cardSignature, $signatureWordwrap, "\n");
$b->annotateImage($draw3, 340, 300, 0, $fixedCardSignature);
$imgName = "images/usercards/test-image.png";
$b->writeImage($imgName);
// Redirect to results page
header("Location: http://sometestsite.com/christmas-card-maker/viewcard.php");
开发者ID:kieranjones,项目名称:christmas-card-maker,代码行数:31,代码来源:cardresult.php

示例9: convert

 /**
  * Convert to output format. This method convert from pdf to specified format with optimizing
  * @throw Exception
  * @access public
  * @param string $outputPath - path to file. May content only path or path with filename
  * @param int/string[=ALL] $page - number of document page wich will be converted into image. If specified 'ALL' - will be converted all pages.
  * @param string $format - output format (see self::getFormats())
  * @param array $resolution - array with x&y resolution DPI
  * @param int $depth - bit depth image
  * @return string/bool[false] - return image path of last converted page
  */
 public function convert($outputPath = '', $page = 'ALL', $format = 'png', $resolution = array('x' => 300, 'y' => 300), $depth = 8)
 {
     if (!Imagick::queryFormats(strtoupper($format))) {
         throw new Exception('Unsupported format');
     }
     $startTime = microtime(true);
     $im = new imagick();
     $im->setResolution($resolution['x'], $resolution['y']);
     $format = strtolower($format);
     $im->setFormat($format);
     if ($outputPath) {
         if (is_dir($outputPath)) {
             $outputPath = $outputPath . pathinfo($this->filePathWithoutType, PATHINFO_FILENAME);
         }
         $outputFileName = $outputPath;
     } else {
         $outputFileName = $this->filePathWithoutType;
     }
     if ($page === 'ALL') {
         $im->readImage($this->filePathWithoutType . '.pdf');
         $im->setImageFormat($format);
         $im->setImageAlphaChannel(11);
         // it's a new constant imagick::ALPHACHANNEL_REMOVE
         $im->mergeImageLayers(Imagick::LAYERMETHOD_FLATTEN);
         $im->setOption($format . ':bit-depth', $depth);
         $im->writeImages($outputFileName . "." . $format, false);
         $logString = '[POINT] File "' . $this->filePathWithoutType . '.pdf" converted to "' . $format . '" with ' . $im->getNumberImages() . ' pages (ex: ' . (microtime(true) - $startTime) . 's)';
         $this->setLog($logString);
         //Optimizing
         if ($format == 'png' && $this->optipngChecking()) {
             $startTime = microtime(true);
             for ($page = $i = 0; $i < $im->getNumberImages(); $i++) {
                 $this->execute('optipng -o=5', $outputFileName . "-" . (int) $i . "." . $format);
             }
             $logString = '[POINT] Files "' . $outputFileName . '-x.' . $format . '" optimized (ex: ' . (microtime(true) - $startTime) . 's)';
             $this->setLog($logString);
         }
     } else {
         $im->readImage($this->filePathWithoutType . '.pdf[' . (int) $page . ']');
         $im->setImageFormat($format);
         $im->setImageAlphaChannel(11);
         // it's a new constant imagick::ALPHACHANNEL_REMOVE
         $im->mergeImageLayers(Imagick::LAYERMETHOD_FLATTEN);
         $im->setOption($format . ':color-type', 2);
         $im->setOption($format . ':bit-depth', $depth);
         $im->writeImage($outputFileName . "-" . (int) $page . "." . $format);
         $logString = '[POINT] File "' . $outputFileName . '.pdf" converted to "' . $format . '" one page (ex: ' . (microtime(true) - $startTime) . 's)';
         $this->setLog($logString);
         //Optimizing
         if ($format == 'png' && $this->optipngChecking()) {
             $startTime = microtime(true);
             $this->execute('optipng -o=5', $outputFileName . "-" . (int) $page . "." . $format);
             $logString = '[POINT] File "' . $outputFileName . "-" . (int) $page . "." . $format . '" optimized (ex: ' . (microtime(true) - $startTime) . 's)';
             $this->setLog($logString);
         }
     }
     if (file_exists($outputFileName . "-" . (int) $page . "." . $format)) {
         return $outputFileName . "-" . (int) $page . "." . $format;
     } else {
         return false;
     }
 }
开发者ID:Kreker,项目名称:doc2image,代码行数:73,代码来源:Doc2Image.php

示例10: system

                $wbshell1 = "xvfb-run --server-args=\"-screen 0, 1024x768x24\" cutycapt --min-width=460 --url=" . $site_url . " --out=" . $img_name;
                $wbshell2 = "xvfb-run --server-args=\"-screen 0, 1024x768x24\" cutycapt --min-width=1024 --url=" . $site_url . " --out=" . $img_name;
            }
        }
        //根据生成图片的大小调用语句
        $wbshell = $picsize == 1 ? $wbshell1 : $wbshell2;
        //执行截图语句
        system($wbshell);
        //exec($wbshell);
        //注:下面的操作仅是对图片进一步进行调整,可以缩小图片体积等,并方便更多的处理,并非必须。
        $im = new imagick($img_name);
        //if($picsize==1) $im->resizeImage(490,0,Imagick::FILTER_LANCZOS,1);
        $im->setImageFormat("png");
        $im->setCompressionQuality(90);
        $img_name2 = 'html2png/' . time() . '.png';
        $im->writeImage($img_name2);
        $im->clear();
        $im->destroy();
        //输出图片连接
        $url_this = dirname('http://' . $_SERVER['SERVER_NAME'] . $_SERVER["REQUEST_URI"]) . '/' . $img_name2;
    } else {
        $url_this = dirname('http://' . $_SERVER['SERVER_NAME'] . $_SERVER["REQUEST_URI"]) . '/google.png';
    }
    ?>
<div class="wrapper" >
<h1>内容生成工具</h1>
<ul>
    <li><?php 
    echo $errinfo;
    ?>
</li>
开发者ID:boxcore,项目名称:ChangWeiBo,代码行数:31,代码来源:result.php

示例11: imgRotate

 /**
  * Rotate image
  *
  * @param  string   $path               image file
  * @param  int      $degree             rotete degrees
  * @param  string   $bgcolor            square background color in #rrggbb format
  * @param  string   $destformat         image destination format
  * @return string|false
  * @author nao-pon
  * @author Troex Nevelin
  **/
 protected function imgRotate($path, $degree, $bgcolor = '#ffffff', $destformat = null)
 {
     if (($s = @getimagesize($path)) == false || $degree % 360 === 0) {
         return false;
     }
     $result = false;
     // try lossless rotate
     if ($degree % 90 === 0 && in_array($s[2], array(IMAGETYPE_JPEG, IMAGETYPE_JPEG2000))) {
         $count = $degree / 90 % 4;
         $exiftran = array(1 => '-9', 2 => '-1', 3 => '-2');
         $jpegtran = array(1 => '90', 2 => '180', 3 => '270');
         $quotedPath = escapeshellarg($path);
         $cmds = array('exiftran -i ' . $exiftran[$count] . ' ' . $path, 'jpegtran -rotate ' . $jpegtran[$count] . ' -copy all -outfile ' . $quotedPath . ' ' . $quotedPath);
         foreach ($cmds as $cmd) {
             if ($this->procExec($cmd) === 0) {
                 $result = true;
                 break;
             }
         }
         if ($result) {
             return $path;
         }
     }
     switch ($this->imgLib) {
         case 'imagick':
             try {
                 $img = new imagick($path);
             } catch (Exception $e) {
                 return false;
             }
             $img->rotateImage(new ImagickPixel($bgcolor), $degree);
             $result = $img->writeImage($path);
             $img->destroy();
             return $result ? $path : false;
             break;
         case 'gd':
             $img = self::gdImageCreate($path, $s['mime']);
             $degree = 360 - $degree;
             list($r, $g, $b) = sscanf($bgcolor, "#%02x%02x%02x");
             $bgcolor = imagecolorallocate($img, $r, $g, $b);
             $tmp = imageRotate($img, $degree, (int) $bgcolor);
             $result = self::gdImage($tmp, $path, $destformat, $s['mime']);
             imageDestroy($img);
             imageDestroy($tmp);
             return $result ? $path : false;
             break;
     }
     return false;
 }
开发者ID:Alex-Bond,项目名称:yii2-elfinder,代码行数:60,代码来源:elFinderVolumeDriver.class.php

示例12: _resizeImagick

 public function _resizeImagick(Model $model, $field, $path, $size, $geometry, $thumbnailPath)
 {
     $srcFile = $path . $model->data[$model->alias][$field];
     $pathInfo = $this->_pathinfo($srcFile);
     $thumbnailType = $imageFormat = $this->settings[$model->alias][$field]['thumbnailType'];
     $isMedia = $this->_isMedia($model, $this->runtime[$model->alias][$field]['type']);
     $image = new imagick();
     if ($isMedia) {
         $image->setResolution(300, 300);
         $srcFile = $srcFile . '[0]';
     }
     $image->readImage($srcFile);
     $height = $image->getImageHeight();
     $width = $image->getImageWidth();
     if (preg_match('/^\\[[\\d]+x[\\d]+\\]$/', $geometry)) {
         // resize with banding
         list($destW, $destH) = explode('x', substr($geometry, 1, strlen($geometry) - 2));
         $image->thumbnailImage($destW, $destH, true);
         $imageGeometry = $image->getImageGeometry();
         $x = ($imageGeometry['width'] - $destW) / 2;
         $y = ($imageGeometry['height'] - $destH) / 2;
         $image->setGravity(Imagick::GRAVITY_CENTER);
         $image->extentImage($destW, $destH, $x, $y);
     } elseif (preg_match('/^[\\d]+x[\\d]+$/', $geometry)) {
         // cropped resize (best fit)
         list($destW, $destH) = explode('x', $geometry);
         $image->cropThumbnailImage($destW, $destH);
     } elseif (preg_match('/^[\\d]+w$/', $geometry)) {
         // calculate heigh according to aspect ratio
         $image->thumbnailImage((int) $geometry - 1, 0);
     } elseif (preg_match('/^[\\d]+h$/', $geometry)) {
         // calculate width according to aspect ratio
         $image->thumbnailImage(0, (int) $geometry - 1);
     } elseif (preg_match('/^[\\d]+l$/', $geometry)) {
         // calculate shortest side according to aspect ratio
         $destW = 0;
         $destH = 0;
         $destW = $width > $height ? (int) $geometry - 1 : 0;
         $destH = $width > $height ? 0 : (int) $geometry - 1;
         $imagickVersion = phpversion('imagick');
         $image->thumbnailImage($destW, $destH, !($imagickVersion[0] == 3));
     }
     if ($isMedia) {
         $thumbnailType = $imageFormat = $this->settings[$model->alias][$field]['mediaThumbnailType'];
     }
     if (!$thumbnailType || !is_string($thumbnailType)) {
         try {
             $thumbnailType = $imageFormat = $image->getImageFormat();
             // Fix file casing
             while (true) {
                 $ext = false;
                 $pieces = explode('.', $srcFile);
                 if (count($pieces) > 1) {
                     $ext = end($pieces);
                 }
                 if (!$ext || !strlen($ext)) {
                     break;
                 }
                 $low = array('ext' => strtolower($ext), 'thumbnailType' => strtolower($thumbnailType));
                 if ($low['ext'] == 'jpg' && $low['thumbnailType'] == 'jpeg') {
                     $thumbnailType = $ext;
                     break;
                 }
                 if ($low['ext'] == $low['thumbnailType']) {
                     $thumbnailType = $ext;
                 }
                 break;
             }
         } catch (Exception $e) {
             $this->log($e->getMessage(), 'upload');
             $thumbnailType = $imageFormat = 'png';
         }
     }
     $fileName = str_replace(array('{size}', '{filename}', '{primaryKey}'), array($size, $pathInfo['filename'], $model->id), $this->settings[$model->alias][$field]['thumbnailName']);
     $destFile = "{$thumbnailPath}{$fileName}.{$thumbnailType}";
     $image->setImageCompressionQuality($this->settings[$model->alias][$field]['thumbnailQuality']);
     $image->setImageFormat($imageFormat);
     if (!$image->writeImage($destFile)) {
         return false;
     }
     $image->clear();
     $image->destroy();
     return true;
 }
开发者ID:ederdsr,项目名称:civisindicadores,代码行数:84,代码来源:UploadBehavior.php

示例13: imgRotate

 /**
  * Rotate image
  *
  * @param  string   $path               image file
  * @param  int      $degree             rotete degrees
  * @param  string   $bgcolor            square background color in #rrggbb format
  * @param  string   $destformat         image destination format
  * @return string|false
  * @author nao-pon
  * @author Troex Nevelin
  **/
 protected function imgRotate($path, $degree, $bgcolor = '#ffffff', $destformat = null)
 {
     if (($s = @getimagesize($path)) == false) {
         return false;
     }
     $result = false;
     switch ($this->imgLib) {
         case 'imagick':
             try {
                 $img = new imagick($path);
             } catch (Exception $e) {
                 return false;
             }
             $img->rotateImage(new ImagickPixel($bgcolor), $degree);
             $result = $img->writeImage($path);
             return $result ? $path : false;
             break;
         case 'gd':
             if ($s['mime'] == 'image/jpeg') {
                 $img = imagecreatefromjpeg($path);
             } elseif ($s['mime'] == 'image/png') {
                 $img = imagecreatefrompng($path);
             } elseif ($s['mime'] == 'image/gif') {
                 $img = imagecreatefromgif($path);
             } elseif ($s['mime'] == 'image/xbm') {
                 $img = imagecreatefromxbm($path);
             }
             $degree = 360 - $degree;
             list($r, $g, $b) = sscanf($bgcolor, "#%02x%02x%02x");
             $bgcolor = imagecolorallocate($img, $r, $g, $b);
             $tmp = imageRotate($img, $degree, (int) $bgcolor);
             if ($destformat == 'jpg' || $destformat == null && $s['mime'] == 'image/jpeg') {
                 $result = imagejpeg($tmp, $path, 100);
             } else {
                 if ($destformat == 'gif' || $destformat == null && $s['mime'] == 'image/gif') {
                     $result = imagegif($tmp, $path, 7);
                 } else {
                     $result = imagepng($tmp, $path, 7);
                 }
             }
             imageDestroy($img);
             imageDestroy($tmp);
             return $result ? $path : false;
             break;
     }
     return false;
 }
开发者ID:serhatozles,项目名称:yii2-elfinder,代码行数:58,代码来源:elFinderVolumeDriver.class.php

示例14: imagick

 if ($p[1] != 'gif') {
     // Открываем watermark
     $watermark = new imagick('./img/watermark.png');
     // узнаем размеры оригинального изображения
     $im_width = $im->getImageWidth();
     $im_height = $im->getImageHeight();
     // узнаем размеры водяного знака
     $watermark_width = $watermark->getImageWidth();
     $watermark_height = $watermark->getImageHeight();
     // посчитать x и y
     $left = $im_width - $watermark_width - 10;
     $top = $im_height - $watermark_height - 10;
     // накладываем watermark на оригинальное изображение
     $im->compositeImage($watermark, imagick::COMPOSITE_OVER, $left, $top);
     // сохраняем оригинал
     $im->writeImage('./images/' . $image_name . '.' . $p[1]);
 } else {
     // сохраняем .gif с учетом анимации
     $im->writeImages('./images/' . $image_name . '.' . $p[1], true);
 }
 // Копируем объект для различных типов
 $large = $im->clone();
 $square = $im->clone();
 // Создаем квадратное изображение 160x160 px
 $square->cropThumbnailImage(160, 160);
 $square->writeImage('./images/' . $image_name . 's' . '.' . $p[1]);
 // Создаем большое изображение с шириной 640 px и переменной высотой
 $large->thumbnailImage(640, 0);
 $large->writeImage('./images/' . $image_name . 'l' . '.' . $p[1]);
 // добавляем имя, расширение, дату загрузки изображения в БД
 // выбираем коллекцию
开发者ID:iSkript,项目名称:Imgur-clone,代码行数:31,代码来源:upload.php

示例15: greateTH

 private function greateTH($file, $th)
 {
     $im = new imagick($_SERVER['DOCUMENT_ROOT'] . "/" . $file);
     $im->cropThumbnailImage(110, 110);
     $im->writeImage($_SERVER['DOCUMENT_ROOT'] . "/" . $th);
 }
开发者ID:pumi11,项目名称:veselkina,代码行数:6,代码来源:PostFile.class.php


注:本文中的imagick::writeImage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。