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


PHP Image::load方法代码示例

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


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

示例1: uploadPicture

 public static function uploadPicture()
 {
     $user_id = Input::get('object_id');
     $type = Input::get('object_type');
     $user_id = Input::get('user_id');
     $uploader = new Utils_Uploader(array('jpeg', 'jpg', 'png'));
     $path = DOCROOT . 'assets/uploads' . DS;
     if (!file_exists($path)) {
         mkdir($path, 0777, true);
     }
     $typeName = Model_Upload_Type::find($type)->types;
     $pic_name = $typeName . "_" . time();
     $original = $path . $pic_name;
     $output = $uploader->handleUploadRename($path, $pic_name);
     if (isset($output['success'])) {
         $original = $path . $output['full_filename'];
         $uploadAll = Model_Upload::forge();
         $uploadAll->user_id = $user_id;
         $uploadAll->type_id = $type;
         $uploadAll->name = $output['full_filename'];
         $uploadAll->original_name = $output['full_filename'];
         $uploadAll->path = $original;
         $uploadAll->save();
         $output['upload_id'] = $uploadAll->id;
         Image::load($original)->preset($typeName)->save($original);
         $localFileName = $path . $output['full_filename'];
         $remoteFileName = DOCROOT . 'assets/uploads/' . DS . $output['full_filename'];
         $output['uri'] = Uri::create('upload/get_image/' . $output['full_filename'] . '/' . $output['upload_id']);
     }
     return $output;
 }
开发者ID:sajans,项目名称:cms,代码行数:31,代码来源:upload___.php

示例2: process

 public function process(Version $version)
 {
     $fr = $version->getFileResource();
     $image = \Image::load($fr->read());
     $fr = $version->getFileResource();
     $width = $this->getMaxWidth();
     $height = $this->getMaxHeight();
     $mode = $this->getConstraintMode();
     $thumbnail = $image->thumbnail(new Box($width, $height), $mode);
     $mimetype = $fr->getMimeType();
     $thumbnailOptions = array();
     switch ($mimetype) {
         case 'image/jpeg':
             $thumbnailType = 'jpeg';
             $thumbnailOptions = array('jpeg_quality' => \Config::get('concrete.misc.default_jpeg_image_compression'));
             break;
         case 'image/png':
             $thumbnailType = 'png';
             break;
         case 'image/gif':
             $thumbnailType = 'gif';
             break;
         case 'image/xbm':
             $thumbnailType = 'xbm';
             break;
         case 'image/vnd.wap.wbmp':
             $thumbnailType = 'wbmp';
             break;
         default:
             $thumbnailType = 'png';
             break;
     }
     $version->updateContents($thumbnail->get($thumbnailType, $thumbnailOptions));
 }
开发者ID:ppiedaderawnet,项目名称:concrete5,代码行数:34,代码来源:ConstrainImageProcessor.php

示例3: cropCoverPhoto

 public function cropCoverPhoto($Croppath, $upload_id)
 {
     $uploader = new Utils_Uploader(array('jpeg', 'jpg', 'png'));
     $uploads = self::find($upload_id);
     $oldpath = $uploads->path;
     $oldname = $uploads->name;
     $uploadTypeModel = Model_Upload_Type::find($uploads->type_id);
     $typeName = $uploadTypeModel->types;
     if (file_exists($oldpath . $oldname)) {
         File::delete($oldpath . $oldname);
     }
     $img = $Croppath;
     $img = str_replace('data:image/png;base64,', '', $img);
     $img = str_replace(' ', '+', $img);
     $data = base64_decode($img);
     $file = $oldpath . "crop_image_" . $upload_id . ".png";
     $original = $oldpath . $oldname;
     //$thumbnail = $path . 'min_' . $newFile;
     $success = file_put_contents($file, $data);
     //Image::load($file)->preset('coverimage')->save($thumbnail); //360 width
     Image::load($file)->preset($typeName)->save($original);
     //1260 width
     File::delete($file);
     return $oldname;
 }
开发者ID:sajans,项目名称:cms,代码行数:25,代码来源:upload.php

示例4: _processMedia

 protected function _processMedia($requestData, $mediaFile, $mediaInfo)
 {
     list($type, $id, $size, $filename) = $requestData;
     App::uses('Image', 'Media.Vendor');
     $image = new Image();
     $aSize = $this->PHMedia->getSizeInfo($size);
     $method = $this->PHMedia->getResizeMethod($size);
     $origImg = $this->PHMedia->getFileName($type, $id, null, $mediaInfo['fname'] . '.' . $mediaInfo['orig_ext']);
     if ($method == 'thumb') {
         $thumb = $this->PHMedia->getFileName($type, $id, null, 'thumb.png');
         if (file_exists($thumb)) {
             $origImg = $thumb;
         }
     }
     if (!file_exists($origImg)) {
         $origImg = ROOT . DS . Configure::read('App.webroot') . DS . 'img' . DS . 'no-photo.jpg';
     }
     $image->load($origImg);
     if ($aSize) {
         $method = $this->PHMedia->getResizeMethod($size);
         $image->{$method}($aSize['w'], $aSize['h']);
     }
     $folder = new Folder(dirname($mediaFile), true, 0755);
     if ($mediaInfo['ext'] == 'jpg') {
         $image->outputJpg($mediaFile);
     } elseif ($mediaInfo['ext'] == 'png') {
         $image->outputPng($mediaFile);
     } else {
         $image->outputGif($mediaFile);
     }
 }
开发者ID:nilBora,项目名称:konstruktor,代码行数:31,代码来源:MediaDispatcher.php

示例5: action_index

 public function action_index()
 {
     $is_chenged = false;
     if ($this->user->bank == null) {
         $this->user->bank = Model_Bank::forge();
         $this->user->bank->user_id = $this->user->id;
         $this->user->bank->save();
     }
     if (Input::post("firstname", null) != null and Security::check_token()) {
         $email = Input::post("email", null);
         if ($email != $this->user->email) {
             $check_user = Model_User::find("first", ["where" => [["email" => $email]]]);
             if ($check_user == null) {
                 $this->email = $email;
             } else {
                 $data["error"] = "This email is already in use.";
             }
         }
         $config = ["path" => DOCROOT . "assets/img/pictures/", 'randomize' => true, 'auto_rename' => true, 'ext_whitelist' => array('img', 'jpg', 'jpeg', 'gif', 'png')];
         Upload::process($config);
         if (Upload::is_valid()) {
             Upload::save();
             $saved_result = Upload::get_files();
             $file_name = $saved_result[0]['saved_as'];
             $image = Image::load($config["path"] . $file_name);
             $image->crop_resize(200, 200)->save($config["path"] . "m_" . $file_name);
             $image->crop_resize(86, 86)->save($config["path"] . "s_" . $file_name);
             $this->user->img_path = $file_name;
         } else {
             $error = Upload::get_errors();
         }
         if (!isset($data["error"])) {
             $this->user->firstname = Input::post("firstname", "");
             $this->user->middlename = Input::post("middlename", "");
             $this->user->lastname = Input::post("lastname", "");
             $this->user->google_account = Input::post("google_account", "");
             $this->user->pr = Input::post("pr", "");
             $this->user->educational_background = Input::post("educational_background", "");
             $this->user->enchantJS = Input::post("enchantJS", 0);
             $this->user->trial = Input::post("trial", 0);
             $this->user->save();
             $this->user->bank->name = Input::post("bank_name", "");
             $this->user->bank->branch = Input::post("bank_branch", "");
             $this->user->bank->account = Input::post("bank_account", "");
             $this->user->bank->number = Input::post("bank_number", "");
             $this->user->bank->etc = Input::post("bank_etc", "");
             $this->user->bank->type = Input::post("bank_type", 0);
             $this->user->bank->save();
             $is_chenged = true;
         }
     }
     $data["user"] = $this->user;
     $data["is_chenged"] = $is_chenged;
     $view = View::forge("teachers/profile", $data);
     $this->template->content = $view;
 }
开发者ID:Trd-vandolph,项目名称:game-bootcamp,代码行数:56,代码来源:profile.php

示例6: update_item

 public function update_item($post_data)
 {
     $upload_type = $this->def('upload_type', 'image');
     $upload_dir = \Config::get($upload_type . '_dir', 'files');
     $files = \Upload::get_files();
     $clean_class = str_replace('\\', '', $this->class);
     foreach ($files as $key => $params) {
         if ($params['field'] == $clean_class . '-' . ($this->item->id ? $this->item->id : 'new') . "-{$this->field}") {
             $idx = $key;
             break;
         }
     }
     if (isset($idx)) {
         \Upload::save(array($idx), $this->def('secure') ? realpath(\Config::get('secure_dir', 'secure') . $upload_dir) : DOCROOT . $upload_dir);
         $errors = \Upload::get_errors();
         if (!isset($errors[$idx])) {
             $files = \Upload::get_files();
             $name = $files[$idx]['saved_as'];
             $path = $files[$idx]['saved_to'];
             if ($upload_type == 'image') {
                 if ($dimensions = $this->def('dimension')) {
                     // resize image
                     $image = \Image::load($path . $name);
                     foreach ($dimensions as $dim) {
                         if (preg_match("/^(?P<width>[0-9]+)x(?P<height>[0-9]+)\$/i", $dim, $matches)) {
                             $image->resize($matches['width'], $matches['height'])->save_pa(null, strtolower("_{$dim}"));
                         }
                     }
                 }
             } elseif ($upload_type == 'audio') {
                 if ($lengths = $this->def('truncate')) {
                     if ($ffmpeg = \Config::get('ffmpeg')) {
                         foreach ($lengths as $len) {
                             // truncate audio track
                             $sample = preg_replace("/^(.+)\\.([^\\.]+)\$/", '$1_sample_' . $len . '.$2', $name);
                             // TODO: make an ffmpeg wrapper class
                             shell_exec("{$ffmpeg} -i " . escapeshellarg($path . $name) . " -t {$length} -acodec copy " . escapeshellarg(DOCROOT . $upload_dir . DS . $sample));
                         }
                     } else {
                         error_log("could not truncate audio: ffmpeg not configured.");
                     }
                 }
             }
             $this->item->{$this->field} = $name;
         } else {
             error_log(print_r($errors, true));
             return array('upload_error' => $this->def('desc') . ' failed to save. Error No. ' . $errors[$idx]['error']);
         }
     }
     return true;
 }
开发者ID:nathanharper,项目名称:fuel_cms_nh,代码行数:51,代码来源:upload.php

示例7: save_thumb

 public function save_thumb()
 {
     $this->view();
     $profile = $this->get('profile');
     if (!is_object($profile) || $profile->getUserID() < 1) {
         return false;
     }
     if (isset($_POST['thumbnail']) && strlen($_POST['thumbnail'])) {
         $thumb = base64_decode($_POST['thumbnail']);
         $image = \Image::load($thumb);
         $profile->updateUserAvatar($image);
     }
     $this->redirect('/account/avatar', 'saved');
 }
开发者ID:ceko,项目名称:concrete5-1,代码行数:14,代码来源:avatar.php

示例8: index

 public function index($type, $id, $size, $filename)
 {
     App::uses('MediaPath', 'Media.Vendor');
     $this->PHMedia = new MediaPath();
     $fname = $this->PHMedia->getFileName($type, $id, $size, $filename);
     $aFName = $this->PHMedia->getFileInfo($filename);
     $this->response->header("Cache-Control", "max-age=2592000, must-revalidate");
     $this->response->header("Expires", gmdate("D, d M Y H:i:s", time() + MONTH) . " GMT");
     $this->response->header("Pragma", "cache");
     if (file_exists($fname)) {
         $this->response->type($aFName['ext']);
         $this->response->file($fname);
         return $this->response;
     }
     App::uses('Image', 'Media.Vendor');
     $image = new Image();
     $aSize = $this->PHMedia->getSizeInfo($size);
     $method = $this->PHMedia->getResizeMethod($size);
     $origImg = $this->PHMedia->getFileName($type, $id, null, $aFName['fname'] . '.' . $aFName['orig_ext']);
     if ($method == 'thumb') {
         $thumb = $this->PHMedia->getFileName($type, $id, null, 'thumb.png');
         if (file_exists($thumb)) {
             $origImg = $thumb;
         }
     }
     if (!file_exists($origImg)) {
         $origImg = ROOT . DS . Configure::read('App.webroot') . DS . 'img' . DS . 'no-photo.jpg';
     }
     $image->load($origImg);
     if ($aSize) {
         $method = $this->PHMedia->getResizeMethod($size);
         $image->{$method}($aSize['w'], $aSize['h']);
     }
     //debug($fname);
     if ($aFName['ext'] == 'jpg') {
         $image->outputJpg($fname);
         $image->outputJpg();
     } elseif ($aFName['ext'] == 'png') {
         $image->outputPng($fname);
         $image->outputPng();
     } else {
         $image->outputGif($fname);
         $image->outputGif();
     }
     exit;
 }
开发者ID:nilBora,项目名称:konstruktor,代码行数:46,代码来源:RouterController.php

示例9: process

 public function process(Version $version)
 {
     switch ($this->getFormat()) {
         case self::FORMAT_JPEG:
             $extension = 'jpg';
         default:
             $extension = 'jpg';
             break;
     }
     if ($extension) {
         $fr = $version->getFileResource();
         $image = \Image::load($fr->read());
         $filename = $version->getFileName();
         $service = \Core::make('helper/file');
         $newFilename = $service->replaceExtension($filename, $extension);
         $version->updateContents($image->get($extension));
         $version->rename($newFilename);
     }
 }
开发者ID:ceko,项目名称:concrete5-1,代码行数:19,代码来源:ForceImageFormatProcessor.php

示例10: resize

 /**
  * Resizes an Image to a given maximum width and height.
  *
  * @param string  $file     - absolute image path
  * @param integer $width    - desired width of the image
  * @param integer $height   - desired height of the image
  * @param string  $mimetype - image type
  *
  * @return boolean - true if success, false otherwise
  */
 public static function resize($file, $width, $height, $mimetype)
 {
     $jit_status = ExtensionManager::fetchStatus(array('handle' => 'jit_image_manipulation'));
     // process image using JIT mode 1
     if ($jit_status[0] === EXTENSION_ENABLED) {
         require_once EXTENSIONS . '/jit_image_manipulation/lib/class.image.php';
         try {
             $image = Image::load($file);
             // if not and Image, stick with original version
             if (!$image instanceof Image) {
                 return false;
             }
         } catch (Exception $e) {
             return false;
         }
         $image->applyFilter('resize', array($width, $height));
         $image->save($file, 85, null, $mimetype);
     }
     return true;
 }
开发者ID:hotdoy,项目名称:EDclock,代码行数:30,代码来源:field.image_upload.php

示例11: index

 public function index($type, $id, $size, $filename)
 {
     App::uses('MediaPath', 'Media.Vendor');
     $this->PHMedia = new MediaPath();
     $fname = $this->PHMedia->getFileName($type, $id, $size, $filename);
     $aFName = $this->PHMedia->getFileInfo($filename);
     if (file_exists($fname)) {
         header('Content-type: image/' . $aFName['ext']);
         echo file_get_contents($fname);
         exit;
     }
     App::uses('Image', 'Media.Vendor');
     $image = new Image();
     $aSize = $this->PHMedia->getSizeInfo($size);
     $method = $this->PHMedia->getResizeMethod($size);
     $origImg = $this->PHMedia->getFileName($type, $id, null, $aFName['fname'] . '.' . $aFName['orig_ext']);
     if ($method == 'thumb') {
         $thumb = $this->PHMedia->getFileName($type, $id, null, 'thumb.png');
         if (file_exists($thumb)) {
             $origImg = $thumb;
         }
     }
     $image->load($origImg);
     if ($aSize) {
         $method = $this->PHMedia->getResizeMethod($size);
         $image->{$method}($aSize['w'], $aSize['h']);
     }
     if ($aFName['ext'] == 'jpg') {
         $image->outputJpg($fname);
         $image->outputJpg();
     } elseif ($aFName['ext'] == 'png') {
         $image->outputPng($fname);
         $image->outputPng();
     } else {
         $image->outputGif($fname);
         $image->outputGif();
     }
     exit;
 }
开发者ID:Fyr,项目名称:frtm,代码行数:39,代码来源:RouterController.php

示例12: action_edit

 /**
  * Действие для редактирования фотографии
  * 
  * @param int $id
  */
 public function action_edit($id = null)
 {
     is_null($id) and \Response::redirect('admin/media/photos/categories');
     if (!($photo = \Model_Media_Photo::find($id, array('related' => 'category')))) {
         \Session::set_flash('error', 'Фотография не найдена.');
         \Response::redirect('admin/media/photos/categories');
     }
     $val = \Model_Media_Photo::validate('edit');
     if ($val->run()) {
         // Загружаем файл
         $config = array('path' => DOCROOT . 'assets/img/gallery', 'randomize' => true, 'ext_whitelist' => array('img', 'jpg', 'jpeg', 'gif', 'png'));
         \Upload::process($config);
         if (\Upload::is_valid()) {
             // Сохраняем файл на диск
             \Upload::save();
             // Меняем размер изображения на 1024px * 768px
             $files = \Upload::get_files();
             $path = $files[0]['saved_to'] . $files[0]['saved_as'];
             \Image::load($path)->resize(1024, 768, true)->save($path);
             // Создаём thumbnail
             $thumb_path = $files[0]['saved_to'] . 'thumbnails/' . $files[0]['saved_as'];
             \Image::load($path)->resize(400, 300, true)->save($thumb_path);
             // Удаляем старые файлы
             unlink(DOCROOT . 'assets/img/gallery/' . $photo->image_path);
             unlink(DOCROOT . 'assets/img/gallery/thumbnails/' . $photo->image_path);
             // Пишем инфу в БД
             $photo->image_path = $files[0]['saved_as'];
             if ($photo->save()) {
                 \Session::set_flash('success', 'Фотография обновлена.');
                 \Response::redirect('admin/media/photos/list/index/' . $photo->category->id);
             } else {
                 \Session::set_flash('error', 'Could not update Media_Photo #' . $id);
             }
         }
     } else {
         if (\Input::method() == 'POST') {
             \Session::set_flash('error', $val->error());
         }
         $this->template->set_global('photo', $photo, false);
     }
     $this->template->title = 'Фотогалерея "' . $photo->category->title . '"';
     $this->template->content = \View::forge('media/photos/list/edit');
 }
开发者ID:alexmon1989,项目名称:fcssadon.ru,代码行数:48,代码来源:list.php

示例13: stdClass

if (!isset($_JPOST->backgroundColor) || $_JPOST->backgroundColor == '') {
    $_JPOST->backgroundColor = new stdClass();
    $_JPOST->backgroundColor->red = 255;
    $_JPOST->backgroundColor->green = 255;
    $_JPOST->backgroundColor->blue = 255;
    $_JPOST->backgroundColor->alpha = 1;
}
imagefill($img->image, 0, 0, imagecolorallocatealpha($img->image, $_JPOST->backgroundColor->red, $_JPOST->backgroundColor->green, $_JPOST->backgroundColor->blue, $_JPOST->backgroundColor->alpha * 127.0));
$img->image_type = IMAGETYPE_PNG;
# Adding our images
for ($i = 0, $icount = count($_JPOST->images); $i < $icount; $i++) {
    # Storing our image
    $img_details = $_JPOST->images[$i];
    # Getting our image
    $tmpimg = new Image();
    $tmpimg->load($img_details->src);
    # Our dimentions
    $x = (int) $img_details->x;
    $y = (int) $img_details->y;
    $width = (int) $img_details->width;
    $height = (int) $img_details->height;
    $rotate = (double) $img_details->rotate;
    switch ($img_details->size) {
        case 'contain':
            # Calaulating our actual widths/heights
            $px = $width / $tmpimg->getWidth();
            $py = $height / $tmpimg->getHeight();
            # Getting our percentages
            if ($px >= $py) {
                $py /= $px;
                $px = 1.0;
开发者ID:nuQuery,项目名称:v1m0-api-image,代码行数:31,代码来源:collage.php

示例14: save_thumb

 /**
  * Save thumbnail
  *
  * params int $id Article-ID
  * params boolean $is_upthumb Upload thumbnail or not
  *
  * @author Nguyen Van Hiep
  * @author Dao Anh Minh
  * @access public
  *
  * @version 1.0
  * @since 1.0
  */
 protected function save_thumb($id, $is_upthumb)
 {
     if (!$is_upthumb) {
         return;
     }
     Upload::save();
     $info = Upload::get_files(0);
     $filepath = $info['saved_to'] . $info['saved_as'];
     $name = 'a' . $id . '_' . str_replace('-', '_', $info['saved_as']);
     $image = Image::load($filepath);
     $image->save($this->dir . $name);
     File::delete($filepath);
     Model_Article::save_thumb($id, $name);
 }
开发者ID:aminh047,项目名称:pepperyou,代码行数:27,代码来源:article_backup.php

示例15: getThumbnail

 /**
  * Returns a path to the specified item, resized and/or cropped to meet max width and height. $obj can either be
  * a string (path) or a file object.
  * Returns an object with the following properties: src, width, height
  * @param mixed $obj
  * @param int $maxWidth
  * @param int $maxHeight
  * @param bool $crop
  */
 public function getThumbnail($obj, $maxWidth, $maxHeight, $crop = false)
 {
     $fID = false;
     $fh = Loader::helper('file');
     if ($obj instanceof File) {
         try {
             $fr = $obj->getFileResource();
             $fID = $obj->getFileID();
             $filename = md5(implode(':', array($fID, $maxWidth, $maxHeight, $crop, $fr->getTimestamp()))) . '.' . $fh->getExtension($fr->getPath());
         } catch (\Exception $e) {
             $filename = '';
         }
     } else {
         $filename = md5(implode(':', array($obj, $maxWidth, $maxHeight, $crop, filemtime($obj)))) . '.' . $fh->getExtension($obj);
     }
     if (!file_exists(Config::get('concrete.cache.directory') . '/' . $filename)) {
         if ($obj instanceof File) {
             $image = \Image::load($fr->read());
         } else {
             $image = \Image::open($obj);
         }
         // create image there
         $this->create($image, Config::get('concrete.cache.directory') . '/' . $filename, $maxWidth, $maxHeight, $crop);
     }
     $src = REL_DIR_FILES_CACHE . '/' . $filename;
     $abspath = Config::get('concrete.cache.directory') . '/' . $filename;
     $thumb = new \stdClass();
     if (isset($abspath) && file_exists($abspath)) {
         $thumb->src = $src;
         $dimensions = getimagesize($abspath);
         $thumb->width = $dimensions[0];
         $thumb->height = $dimensions[1];
         return $thumb;
     }
 }
开发者ID:ngreimel,项目名称:kovent,代码行数:44,代码来源:ImageHelper.php


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