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


PHP Imagick::cropThumbnailImage方法代碼示例

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


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

示例1: index

 public function index()
 {
     $ps = array();
     $user = $this->session->all_userdata();
     if (isset($_POST['submit']) && isset($user) && isset($user['users_id']) && isset($_FILES['uploaded_image']['tmp_name'])) {
         $imageFile = time() . '.' . end(explode(".", $_FILES['uploaded_image']['name']));
         $photoData = $_POST['photo'];
         $image = new Imagick($_FILES['uploaded_image']['tmp_name']);
         $height = $image->getImageHeight();
         $width = $image->getImageWidth();
         if ($width > 800 || $height > 800) {
             if ($height < $width) {
                 $image->scaleImage(800, 0);
             } else {
                 $image->scaleImage(0, 600);
             }
         }
         $image->writeImage('./storage/photos/b/' . $imageFile);
         $image->cropThumbnailImage(100, 100);
         $image->writeImage('./storage/thumbs/' . $imageFile);
         $ps['photo_b'] = '/storage/photos/b/' . $imageFile;
         $ps['thumb'] = '/storage/thumbs/' . $imageFile;
         $data = array('iname' => $photoData['iname'] ? $photoData['iname'] : 'noname', 'idesc' => $photoData['idesc'] ? $photoData['idesc'] : '', 'path' => '/storage/photos/', 'file' => $imageFile, 'thumb' => $ps['thumb'], 'add_date' => time(), 'allow_comments' => isset($photoData['allow_comments']) ? 1 : 0, 'users_id' => $user['users_id']);
         $this->db->insert('photos', $data);
         $photos_id = $this->db->insert_id();
         $this->load->model('m_users');
         $this->load->model('m_logs');
         $this->m_users->update(array('num_photos' => $user['num_photos'] + 1), $user['users_id']);
         $this->m_logs->add(array('users_id' => $user['users_id'], 'action' => 1, 'object_type' => 2, 'object_id' => $photos_id));
     }
     $ps['_activeMenu'] = 'upload';
     $this->tpl->view('frontend/upload/', $ps);
 }
開發者ID:randix0,項目名稱:DEVils,代碼行數:33,代碼來源:uploader.php

示例2: copyResizedImage

 static function copyResizedImage($inputFile, $outputFile, $width, $height = null, $crop = true)
 {
     if (extension_loaded('gd')) {
         $image = new GD($inputFile);
         if ($height) {
             if ($width && $crop) {
                 $image->cropThumbnail($width, $height);
             } else {
                 $image->resize($width, $height);
             }
         } else {
             $image->resize($width);
         }
         return $image->save($outputFile);
     } elseif (extension_loaded('imagick')) {
         $image = new \Imagick($inputFile);
         if ($height && !$crop) {
             $image->resizeImage($width, $height, \Imagick::FILTER_LANCZOS, 1, true);
         } else {
             $image->resizeImage($width, null, \Imagick::FILTER_LANCZOS, 1);
         }
         if ($height && $crop) {
             $image->cropThumbnailImage($width, $height);
         }
         return $image->writeImage($outputFile);
     } else {
         throw new HttpException(500, 'Please install GD or Imagick extension');
     }
 }
開發者ID:nanodesu88,項目名稱:easyii,代碼行數:29,代碼來源:Image.php

示例3: create_thumb

function create_thumb($source_file, $thumb_file, $edge = THUMBNAIL_CROP_EDGE, &$src_w = NULL, &$src_h = NULL)
{
    $composite_img = new Imagick($source_file);
    $blank_img = new Imagick();
    $src_w = $composite_img->getImageWidth();
    $src_h = $composite_img->getImageHeight();
    if ($src_h > $edge && $src_w > $edge) {
        $composite_img->cropThumbnailImage($edge, $edge);
        $composite_img->setImageFormat('jpeg');
        $composite_img->writeImage($thumb_file);
        $composite_img->clear();
        $blank_img = $composite_img;
    } else {
        $blank_img->newImage($edge, $edge, new ImagickPixel('#DEF'), "jpg");
        if ($src_w > $src_h) {
            $crop_x = $src_w / 2 - $edge / 2;
            $crop_y = 0;
            $offset_x = 0;
            $offset_y = $edge / 2 - $src_h / 2;
        } else {
            $crop_x = 0;
            $crop_y = $src_h / 2 - $edge / 2;
            $offset_x = $edge / 2 - $src_w / 2;
            $offset_y = 0;
        }
        $composite_img->cropImage($edge, $edge, $crop_x, $crop_y);
        $blank_img->compositeImage($composite_img, Imagick::COMPOSITE_OVER, $offset_x, $offset_y);
        $blank_img->setImageFormat('jpeg');
        $blank_img->writeImage($thumb_file);
        $blank_img->clear();
    }
    return $blank_img;
}
開發者ID:hoogle,項目名稱:ttt,代碼行數:33,代碼來源:index.php

示例4: thumbnailCreator

 private function thumbnailCreator($imageAddress, $targetDirectory, $targetName)
 {
     $config = $this->config;
     $image = new \Imagick($imageAddress);
     $image->cropThumbnailImage($config['general']['image_tumbnail_width'], $config['general']['image_tumbnail_height']);
     $image->writeImage($targetDirectory . "/thumb_" . $targetName);
     return "thumb_" . $targetName;
 }
開發者ID:roozbeh360,項目名稱:MotorbikeBundle,代碼行數:8,代碼來源:ImageService.php

示例5: createThumbnail

 function createThumbnail($field, $x, $y)
 {
     // Create entry for thumbnail.
     $thumb = $this->ref($field, 'link');
     if (!$thumb->loaded()) {
         $thumb->set('filestore_volume_id', $this->get('filestore_volume_id'));
         $thumb->set('original_filename', 'thumb_' . $this->get('original_filename'));
         $thumb->set('filestore_type_id', $this->get('filestore_type_id'));
         $thumb['filename'] = $thumb->generateFilename();
     }
     if (class_exists('\\Imagick', false)) {
         $image = new \Imagick($this->getPath());
         //$image->resizeImage($x,$y,\Imagick::FILTER_LANCZOS,1,true);
         $image->cropThumbnailImage($x, $y);
         $this->hook("beforeThumbSave", array($thumb));
         $image->writeImage($thumb->getPath());
     } elseif (function_exists('imagecreatefromjpeg')) {
         list($width, $height, $type) = getimagesize($this->getPath());
         ini_set("memory_limit", "1000M");
         $a = array(null, 'gif', 'jpeg', 'png');
         $type = @$a[$type];
         if (!$type) {
             throw $this->exception('This file type is not supported');
         }
         //saving the image into memory (for manipulation with GD Library)
         $fx = "imagecreatefrom" . $type;
         $myImage = $fx($this->getPath());
         $thumbSize = $x;
         // only supports rectangles
         if ($x != $y && 0) {
             throw $this->exception('Model_Image currently does not support non-rectangle thumbnails with GD extension')->addMoreInfo('x', $x)->addMoreInfo('y', $y);
         }
         // calculating the part of the image to use for thumbnail
         if ($width > $height) {
             $y = 0;
             $x = ($width - $height) / 2;
             $smallestSide = $height;
         } else {
             $x = 0;
             $y = ($height - $width) / 2;
             $smallestSide = $width;
         }
         // copying the part into thumbnail
         $myThumb = imagecreatetruecolor($thumbSize, $thumbSize);
         imagecopyresampled($myThumb, $myImage, 0, 0, $x, $y, $thumbSize, $thumbSize, $smallestSide, $smallestSide);
         //final output
         imagejpeg($myThumb, $thumb->getPath());
         imageDestroy($myThumb);
         imageDestroy($myImage);
     } else {
         // No Imagemagick support. Ignore resize
         $thumb->import($this->getPath(), 'copy');
     }
     $thumb->save();
     // update size and chmod
 }
開發者ID:xavocvijay,項目名稱:atkschool,代碼行數:56,代碼來源:Image.php

示例6: generateThumbnail

 /**
  * Generate a thumbnail from an object and return the ID of the new object.
  *
  * @param string $id
  * @param int $width
  * @param int $height
  *
  * @return string
  */
 public function generateThumbnail($id, $width, $height = null)
 {
     if ($height === null) {
         $height = $width;
     }
     $temp = $this->container->download($id);
     $img = new \Imagick($temp->getPath());
     $img->cropThumbnailImage($width, $height);
     $img->writeImage();
     return $this->container->upload($temp);
 }
開發者ID:radnan,項目名稱:rdn-upload,代碼行數:20,代碼來源:Uploads.php

示例7: resize_image

function resize_image($file, $w, $h, $crop = FALSE)
{
    // @param file, width, height, crop
    // Resize an image using Imagick
    $img = new Imagick($file);
    if ($crop) {
        $img->cropThumbnailImage($w, $h);
    } else {
        $img->thumbnailImage($w, $h, TRUE);
    }
    return $img;
}
開發者ID:rechner,項目名稱:taxidi-web,代碼行數:12,代碼來源:register.php

示例8: resize_crop

 public function resize_crop($width, $height)
 {
     if (!$this->info['width'] || !$this->info['height']) {
         return;
     }
     //Crop every other image
     for ($r = 0; $r < count($this->image); $r++) {
         $this->image->nextImage();
         $this->image->cropThumbnailImage($width, $height);
     }
     $this->info['width'] = $width;
     $this->info['height'] = $height;
 }
開發者ID:NareshChennuri,項目名稱:pyng,代碼行數:13,代碼來源:Imagick.php

示例9: _imageResizeAndSave

 protected function _imageResizeAndSave($object)
 {
     $path = APPLICATION_ROOT . '/public_html/images/topcontentblock/';
     $system->lng = $this->_getParam('lng');
     $adapter = new Zend_File_Transfer_Adapter_Http();
     $adapter->setDestination($path);
     $adapter->setOptions(array('ignoreNoFile' => true));
     if (!$adapter->receive()) {
         $msgr = Sanmax_MessageStack::getInstance('SxModule_Topcontentblock_Validator');
         $msgr->addMessage('file', $adapter->getMessages(), 'title');
     }
     if ($object->getPicture() == null) {
         $object->setPicture('');
     }
     $files = $adapter->getFileInfo();
     foreach ($files as $file) {
         if (!$file['tmp_name']) {
             continue;
         }
         $path0 = $path . "253X115/";
         $path1 = $path . "1263X575/";
         $path2 = $path . "1263X325/";
         $filename = $object->createThumbName($file['name']) . '_' . time() . '.jpg';
         $image = new Imagick($file['tmp_name']);
         $image->cropThumbnailImage(253, 115);
         $image->setCompression(Imagick::COMPRESSION_JPEG);
         $image->setImageCompressionQuality(100);
         $image->setImageFormat('jpeg');
         $image->writeImage($path0 . $filename);
         $image->clear();
         $image->destroy();
         $image = new Imagick($file['tmp_name']);
         $image->cropThumbnailImage(1263, 575);
         $image->setCompression(Imagick::COMPRESSION_JPEG);
         $image->setImageCompressionQuality(75);
         $image->setImageFormat('jpeg');
         $image->writeImage($path1 . $filename);
         $image->clear();
         $image->destroy();
         $image = new Imagick($file['tmp_name']);
         $image->cropThumbnailImage(1263, 325);
         $image->setCompression(Imagick::COMPRESSION_JPEG);
         $image->setImageCompressionQuality(75);
         $image->setImageFormat('jpeg');
         $image->writeImage($path2 . $filename);
         $image->clear();
         $image->destroy();
         unlink($file['tmp_name']);
         $object->setPicture($filename);
     }
 }
開發者ID:sonvq,項目名稱:2015_freelance6,代碼行數:51,代碼來源:TopcontentblockController.php

示例10: _imageResizeAndSave

 protected function _imageResizeAndSave($object)
 {
     $path = APPLICATION_ROOT . '/public_html/images/eyecatchers/';
     $system->lng = $this->_getParam('lng');
     $adapter = new Zend_File_Transfer_Adapter_Http();
     $adapter->setDestination($path);
     $adapter->setOptions(array('ignoreNoFile' => true));
     if (!$adapter->receive()) {
         $msgr = Sanmax_MessageStack::getInstance('SxModule_Eyecatchers_Validator');
         $msgr->addMessage('file', $adapter->getMessages(), 'title');
     }
     if ($object->getPicture() == null) {
         $object->setPicture('');
     }
     $files = $adapter->getFileInfo();
     foreach ($files as $file) {
         if (!$file['tmp_name']) {
             continue;
         }
         $path0 = $path . "253x115/";
         $path1 = $path . "980x450/";
         if (!is_dir($path0)) {
             mkdir($path0, 0777, true);
         }
         if (!is_dir($path1)) {
             mkdir($path1, 0777, true);
         }
         $filename = $object->createThumbName($file['name']) . '_' . time() . '.png';
         $image = new Imagick($file['tmp_name']);
         $image->cropThumbnailImage(253, 115);
         $image->setCompression(Imagick::COMPRESSION_JPEG);
         $image->setImageCompressionQuality(100);
         $image->setBackgroundColor(new ImagickPixel('transparent'));
         $image->setImageFormat('png32');
         $image->writeImage($path0 . $filename);
         $image->clear();
         $image->destroy();
         $image = new Imagick($file['tmp_name']);
         $image->cropThumbnailImage(980, 450);
         $image->setCompression(Imagick::COMPRESSION_JPEG);
         $image->setImageCompressionQuality(75);
         $image->setBackgroundColor(new ImagickPixel('transparent'));
         $image->setImageFormat('png32');
         $image->writeImage($path1 . $filename);
         $image->clear();
         $image->destroy();
         unlink($file['tmp_name']);
         $object->setPicture($filename);
     }
 }
開發者ID:sonvq,項目名稱:2015_freelance6,代碼行數:50,代碼來源:EyecatchersController.php

示例11: background

 private function background()
 {
     if ($this->config['method'] === 'image' && is_file($this->config['image'])) {
         $image = new \Imagick();
         try {
             $image->readImage($this->config['image']);
             $image->setImageType(\Imagick::IMGTYPE_TRUECOLORMATTE);
         } catch (\ImagickException $e) {
             throw new Exception\NotSupportedException("Ivatar - ({$this->config['image']}) unable to open image.");
         }
         $image->cropThumbnailImage($this->options['size'], $this->options['size']);
         $this->ivatar->compositeImage($image, \Imagick::COMPOSITE_DEFAULT, 0, 0);
     }
 }
開發者ID:cloudratha,項目名稱:ivatar,代碼行數:14,代碼來源:Driver.php

示例12: start

 public function start()
 {
     $data['_activeMenu'] = 'admin';
     ignore_user_abort(true);
     set_time_limit(0);
     $offset = 0;
     $limit = 10;
     $this->db->where('updated', 0);
     $this->db->where('is_deleted', 0);
     $query = $this->db->get('photos_il', $limit, $offset);
     $photos = $query->result_array();
     while (count($photos) > 0) {
         foreach ($photos as $p) {
             $img = $p['img'];
             $imageFile = str_replace('http://photo.ilich.in.ua/upload/', '', $img);
             echo '<p>' . $imageFile . '</p>';
             if (file_exists('./upload/' . $imageFile)) {
                 $image = new Imagick('./upload/' . $imageFile);
                 //$imageFile=time().'.'.end(explode(".", $_FILES['uploaded_image']['name']));
                 $height = $image->getImageHeight();
                 $width = $image->getImageWidth();
                 if ($width > 800 || $height > 800) {
                     if ($height < $width) {
                         $image->scaleImage(800, 0);
                     } else {
                         $image->scaleImage(0, 600);
                     }
                 }
                 $image->writeImage('./storage_2/photos/b/' . $imageFile);
                 $image->cropThumbnailImage(100, 100);
                 $image->writeImage('./storage_2/thumbs/' . $imageFile);
                 $this->db->where('phid', $p['phid']);
                 $this->db->update('photos_il', array('updated' => 1));
             } else {
                 $this->db->where('phid', $p['phid']);
                 $this->db->update('photos_il', array('is_deleted' => 1));
             }
         }
         $this->db->where('updated', 0);
         $query = $this->db->get('photos_il', $limit, $offset);
         $photos = $query->result_array();
     }
     //$this->tpl->view('backend/install/', $data);
 }
開發者ID:randix0,項目名稱:DEVils,代碼行數:44,代碼來源:patch.php

示例13: createThumbnail

 function createThumbnail($field, $x, $y)
 {
     // Create entry for thumbnail.
     $thumb = $this->ref($field, 'link');
     if (!$thumb->loaded()) {
         $thumb->set('filestore_volume_id', $this->get('filestore_volume_id'));
         $thumb->set('original_filename', 'thumb_' . $this->get('original_filename'));
         $thumb->set('filestore_type_id', $this->get('filestore_type_id'));
         $thumb['filename'] = $thumb->generateFilename();
     }
     if (class_exists('\\Imagick', false)) {
         $image = new \Imagick($this->getPath());
         //$image->resizeImage($x,$y,\Imagick::FILTER_LANCZOS,1,true);
         $image->cropThumbnailImage($x, $y);
         $this->hook("beforeThumbSave", array($thumb));
         $image->writeImage($thumb->getPath());
     } else {
         // No Imagemagick support. Ignore resize
         $thumb->import($this->getPath(), 'copy');
     }
     $thumb->save();
     // update size and chmod
 }
開發者ID:romaninsh,項目名稱:atkSchool,代碼行數:23,代碼來源:Image.php

示例14: isset

    	(isset($_POST['comment'])) ? $comment = $_POST['comment'] : $comment = '';
    	(isset($_POST['oldFileName'])) ? $oldFileName = $_POST['oldFileName'] : $oldFileName = '';*/
    isset($_POST['newFileName']) ? $newFileName = $_POST['newFileName'] : ($newFileName = '');
    isset($_POST['pureNewFileName']) ? $pureNewFileName = $_POST['pureNewFileName'] : ($pureNewFileName = '');
    isset($_POST['fileType']) ? $fileType = $_POST['fileType'] : ($fileType = '');
    isset($_POST['path']) ? $path = $_POST['path'] : ($path = '');
    if (empty($path)) {
        $upath = dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'uploads' . DIRECTORY_SEPARATOR . $_FILES['file']['name'];
    } else {
        $path = str_replace("/", DIRECTORY_SEPARATOR, $path);
        $upath = dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . $path;
    }
    //echo $upath;
    $tempPath = $_FILES['file']['tmp_name'];
    $uploadPath = dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'uploads' . DIRECTORY_SEPARATOR . $_FILES['file']['name'];
    //move_uploaded_file( $tempPath, $uploadPath );
    move_uploaded_file($tempPath, $upath . $newFileName);
    $thumb = new Imagick($upath . $newFileName);
    //if($fileType != 'jpg')
    //	$thumb->writeImage($upath . $pureNewFileName . '.jpg');
    $thumb->cropThumbnailImage(160, 90);
    $thumb->setImageFormat('jpeg');
    $thumb->writeImage($upath . '_thumbs' . DIRECTORY_SEPARATOR . 't_' . $pureNewFileName . '.jpg');
    $thumb->destroy();
    exec("C:\\ImageMagick\\convert.exe " . $upath . $newFileName . " -resize \"1024x1024>\" " . $upath . $pureNewFileName . "_1024.jpg");
    $answer = array('answer' => 'File transfer completed');
    $json = json_encode($answer);
    echo $json;
} else {
    echo 'No files';
}
開發者ID:Brakebein,項目名稱:DokuVis,代碼行數:31,代碼來源:upload.php

示例15: foreach

			color: #337372;
			text-decoration: none;
		}

	</style>
</head>
<body>';
if (class_exists('Imagick')) {
    foreach (glob("*.*") as $filename) {
        if (!file_exists('thumb')) {
            mkdir('thumb');
        }
        if (!file_exists('thumb/' . $filename) && in_array(end(explode('.', $filename)), $allowed_filetypes)) {
            $imagick = new Imagick($filename);
            $imagick->thumbnailImage(null, 100);
            $imagick->cropThumbnailImage(100, 100);
            $imagick->writeImage('thumb/' . $filename);
            $imagick->clear();
            $imagick->destroy();
            print '<img src="thumb/' . urlencode($filename) . '" alt="" class="thumb" data-filename="' . urlencode($filename) . '" />';
        } elseif (in_array(end(explode('.', $filename)), $allowed_filetypes)) {
            print '<img src="thumb/' . urlencode($filename) . '" alt="" class="thumb" data-filename="' . urlencode($filename) . '" />';
        }
    }
    foreach (glob("thumb/*.*") as $filename) {
        if (!file_exists(basename($filename))) {
            unlink($filename);
        }
    }
} else {
    print '
開發者ID:naftis,項目名稱:Noda,代碼行數:31,代碼來源:index.php


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