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


PHP Image::open方法代码示例

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


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

示例1: avatar

 public function avatar()
 {
     $uid = $this->request->get('uid');
     $size = $this->request->get('s');
     if (!is_numeric($uid)) {
         Typecho_Common::error(404);
         exit;
     }
     $path = __TYPECHO_ROOT_DIR__ . Widget_Common::getAvatarPath($uid);
     $path .= $uid . '.jpg';
     if (!is_file($path)) {
         $path = __TYPECHO_ROOT_DIR__ . '/usr/avatar/default.jpg';
     }
     require_once __TYPECHO_ROOT_DIR__ . '/var/Util/Image.php';
     $image = new Image();
     $image->open($path);
     $type = $image->type();
     if (is_numeric($size)) {
         $image->thumb($size, $size);
     }
     header('Content-Type:image/' . $type . ';');
     //输出图像
     if ('jpeg' == $type || 'jpg' == $type) {
         // 采用jpeg方式输出
         imagejpeg($image->showImg());
     } elseif ('gif' == $type) {
         imagegif($image->showImg());
     } else {
         $fun = 'image' . $type;
         $fun($image->showImg());
     }
 }
开发者ID:dccecc,项目名称:typecho,代码行数:32,代码来源:Action.php

示例2: thumbnail

 public function thumbnail()
 {
     $siteUrl = Typecho_Widget::widget('Widget_Options')->siteUrl;
     $url = $this->request->get('url');
     $size = $this->request->get('s');
     if ($size) {
         $size = explode('x', $size);
         $size[1] = isset($size[1]) ? $size[1] : $size[0];
     } else {
         $options = Typecho_Widget::widget('Widget_Options')->plugin('Tools');
         $width = $options->thumbnailwidth;
         $height = $options->thumbnailheight;
         $size = array($width, $height);
     }
     $path = __TYPECHO_ROOT_DIR__ . $url;
     if (!is_file($path)) {
         exit;
     }
     require_once 'Image.php';
     $image = new Image();
     $image->open($path);
     $type = $image->type();
     $image->thumb($size[0], $size[1], 3);
     header('Content-Type:image/' . $type . ';');
     //输出图像
     if ('jpeg' == $type || 'jpg' == $type) {
         // 采用jpeg方式输出
         imagejpeg($image->showImg());
     } elseif ('gif' == $type) {
         imagegif($image->showImg());
     } else {
         $fun = 'image' . $type;
         $fun($image->showImg());
     }
 }
开发者ID:hongweipeng,项目名称:cool_blog,代码行数:35,代码来源:Action.php

示例3: update_avatar

 public function update_avatar($uID = false)
 {
     $this->setupUser($uID);
     if (!Loader::helper('validation/token')->validate()) {
         throw new Exception(Loader::helper('validation/token')->getErrorMessage());
     }
     if ($this->canEditAvatar) {
         $av = Loader::helper('concrete/avatar');
         if (is_uploaded_file($_FILES['avatar']['tmp_name'])) {
             $image = \Image::open($_FILES['avatar']['tmp_name']);
             $image = $image->thumbnail(new Box(Config::get('concrete.icons.user_avatar.width'), Config::get('concrete.icons.user_avatar.height')));
             $this->user->updateUserAvatar($image);
         } else {
             if ($_POST['task'] == 'clear') {
                 $this->user->update(array('uHasAvatar' => 0));
             }
         }
     } else {
         throw new Exception(t('Access Denied.'));
     }
     $ui = UserInfo::getByID($uID);
     // avatar doesn't reload automatically
     $sr = new UserEditResponse();
     $sr->setUser($this->user);
     $sr->setMessage(t('Avatar saved successfully.'));
     $html = $av->outputUserAvatar($ui);
     $sr->setAdditionalDataAttribute('imageHTML', $html);
     $sr->outputJSON();
 }
开发者ID:ceko,项目名称:concrete5-1,代码行数:29,代码来源:search.php

示例4: update_avatar

 public function update_avatar($uID = false)
 {
     $this->setupUser($uID);
     if (!$this->app->make('helper/validation/token')->validate()) {
         throw new Exception($this->app->make('helper/validation/token')->getErrorMessage());
     }
     if ($this->canEditAvatar) {
         $file = $this->request->files->get('avatar');
         if ($file !== null) {
             /* @var \Symfony\Component\HttpFoundation\File\UploadedFile $file */
             if (!$file->isValid()) {
                 throw new Exception($file->getErrorMessage());
             }
             $image = \Image::open($file->getPathname());
             $config = $this->app->make('config');
             $image = $image->thumbnail(new Box($config->get('concrete.icons.user_avatar.width'), $config->get('concrete.icons.user_avatar.height')));
             $this->user->updateUserAvatar($image);
         } elseif ($this->request->post('task') == 'clear') {
             $this->user->update(['uHasAvatar' => 0]);
         }
     } else {
         throw new Exception(t('Access Denied.'));
     }
     $ui = UserInfo::getByID($uID);
     // avatar doesn't reload automatically
     $sr = new UserEditResponse();
     $sr->setUser($this->user);
     $sr->setMessage(t('Avatar saved successfully.'));
     $av = $this->user->getUserAvatar();
     $html = $av->output();
     $sr->setAdditionalDataAttribute('imageHTML', $html);
     $sr->outputJSON();
 }
开发者ID:ppiedaderawnet,项目名称:concrete5,代码行数:33,代码来源:search.php

示例5: postProfil

 public function postProfil()
 {
     $validate = Validator::make(Input::all(), ['adsoyad' => 'required', 'email' => 'required|email|unique:users,email,' . Auth::user()->id . '', 'profil' => 'mimes:jpg,png,gif,jpeg']);
     $messages = $validate->messages();
     if ($validate->fails()) {
         return Redirect::back()->with(array('mesaj' => 'true', 'title' => 'Doğrulama Hatası', 'text' => '' . $messages->first() . '', 'type' => 'error'));
     }
     $user = User::findOrFail(Auth::user()->id);
     $user->namesurname = Input::get('adsoyad');
     if (Input::has('password')) {
         $user->password = Hash::make(Input::get('password'));
         $user->save();
     }
     $user->email = Input::get('email');
     if (Input::hasFile('profil')) {
         if (Auth::user()->profil != '') {
             File::delete('Backend/avatar/' . Auth::user()->profil . '');
         }
         $profil = Input::file('profil');
         $dosyaadi = $profil->getClientOriginalName();
         $uzanti = $profil->getClientOriginalExtension();
         $isim = Str::slug($dosyaadi) . Str::slug(str_random(5)) . '.' . $uzanti;
         $dosya = $profil->move('Backend/avatar/', $isim);
         $image = Image::open('Backend/avatar/' . $isim)->resize(80, 80)->save();
         $user->profil = $isim;
         $user->save();
     }
     $user->save();
     if ($user->save()) {
         return Redirect::back()->with(array('mesaj' => 'true', 'title' => 'Kullanıcı Güncellendi', 'text' => 'Kullanıcı Başarı İle Güncellendi', 'type' => 'success'));
     } else {
         return Redirect::back()->with(array('mesaj' => 'true', 'title' => 'Kullanıcı Güncellenemedi', 'text' => 'Kullanıcı Güncellenirken Sorun İle Karşılaşıldı', 'type' => 'error'));
     }
 }
开发者ID:kaanbostanci,项目名称:SozlukProje,代码行数:34,代码来源:PanelController.php

示例6: testSaveInBmp

 /**
  * Test
  *
  * @return void
  */
 public function testSaveInBmp()
 {
     $savingPath = $this->directory . 'saving-test.bmp';
     $this->object->open($this->directory . 'test.png');
     $this->object->resize(50, 50);
     $this->assertFalse($this->object->save($savingPath));
 }
开发者ID:gotcms,项目名称:gotcms,代码行数:12,代码来源:ImageTest.php

示例7: placeOver

 public function placeOver(Image $background, $posX, $posY)
 {
     $background->open();
     $this->open();
     imagecopy($background->getResource(), $this->getResource(), $posX, $posY, 0, 0, $this->getWidth(), $this->getHeight());
     $filepath = $background->getFilepath();
     return $this->_writeImageToDisk($filepath, $background->getResource(), $background->getType());
 }
开发者ID:mswagencia,项目名称:image,代码行数:8,代码来源:Image.php

示例8: completeAuthentication

 public function completeAuthentication(User $u)
 {
     $ui = \UserInfo::getByID($u->getUserID());
     if (!$ui->hasAvatar()) {
         try {
             $image = \Image::open($this->getExtractor()->getImageURL());
             $ui->updateUserAvatar($image);
         } catch (\Imagine\Exception\InvalidArgumentException $e) {
             \Log::addNotice("Unable to fetch user images in Google Authentication Type, is allow_url_fopen disabled?");
         } catch (\Exception $e) {
         }
     }
     return parent::completeAuthentication($u);
 }
开发者ID:ppiedaderawnet,项目名称:concrete5,代码行数:14,代码来源:controller.php

示例9: storeCover

 public function storeCover(BookInterface $book, $cover)
 {
     Storage::disk('book_local')->put("{$book->id}/Resources/Templates/ebook/cover.jpg", File::get($cover));
     Storage::disk('book_local')->put("{$book->id}/Resources/Templates/cover.jpg", File::get($cover));
     $print_path = storage_path("books/{$book->id}/Resources/Templates/print");
     if (!is_dir($print_path)) {
         mkdir($print_path, 0775, true);
     }
     $img = new \Imagick(storage_path("books/{$book->id}/Resources/Templates/ebook/cover.jpg"));
     $img->setImageFormat("pdf");
     $img->writeImage(storage_path("books/{$book->id}/Resources/Templates/print/cover.pdf"));
     $thumbnail = \Image::open(storage_path("books/{$book->id}/Resources/Templates/ebook/cover.jpg"))->thumbnail(new Box(356, 522));
     $thumbnail->save(public_path("books/thumbs/{$book->id}.jpg"));
     $thumbnail = \Image::open(storage_path("books/{$book->id}/Resources/Templates/ebook/cover.jpg"))->thumbnail(new Box(138, 230));
     $thumbnail->save(public_path("books/thumbs/{$book->id}_small.jpg"));
 }
开发者ID:codeedu,项目名称:laravel52-carnaval,代码行数:16,代码来源:BookService.php

示例10: shrink

 /**
  * create a thumbnail
  *
  * @param string the full path to the original file
  * @param string the pull path to write the thumbnail
  * @param boolean TRUE to resize to 60x60
  * @param boolean TRUE to see error messages, if any
  * @return TRUE on success, FALSE on error
  */
 public static function shrink($original, $target, $fixed = FALSE, $verbose = TRUE)
 {
     global $context;
     $file_name = basename($original);
     $open = Image::open($original);
     if ($open === FALSE) {
         return FALSE;
     }
     list($image, $image_information) = $open;
     // actual width
     $width = $image_information[0];
     // standard width
     if ($fixed) {
         $maximum_width = 60;
     } elseif (isset($context['thumbnail_width']) && $context['thumbnail_width'] >= 32) {
         $maximum_width = $context['thumbnail_width'];
     } else {
         $maximum_width = 60;
     }
     // actual height
     $height = $image_information[1];
     // standard height
     if ($fixed) {
         $maximum_height = 60;
     } elseif (isset($context['thumbnail_height']) && $context['thumbnail_height'] >= 32) {
         $maximum_height = $context['thumbnail_height'];
     } else {
         $maximum_height = 60;
     }
     // assume resize is not necessary
     $thumbnail_height = $height;
     $thumbnail_width = $width;
     // the image is laid vertically
     if ($height > $width) {
         // set the thumbnail size
         if ($height > $maximum_height) {
             $thumbnail_height = $maximum_height;
             $thumbnail_width = $width * $thumbnail_height / $height;
         }
         // the image is laid horizontally
     } else {
         // set the thumbnail size
         if ($width > $maximum_width) {
             $thumbnail_width = $maximum_width;
             $thumbnail_height = $height * $thumbnail_width / $width;
         }
     }
     // create target folder for the thumbnail
     if ($target_path = dirname($target)) {
         Safe::make_path($target_path);
     }
     // we already have a small image
     if ($thumbnail_width == $width && $thumbnail_height == $height) {
         // copy file content to the thumbnail
         if (!copy($original, $target)) {
             if ($verbose) {
                 Logger::error(sprintf(i18n::s('Cannot copy image to %s'), $target));
             }
             return FALSE;
         }
         // this will be filtered by umask anyway
         Safe::chmod($target, $context['file_mask']);
         // job done
         return TRUE;
     }
     // create the thumbnail in memory
     $thumbnail = NULL;
     if (Image::use_magic()) {
         $thumbnail = $image->resizeImage($thumbnail_width, $thumbnail_height, Imagick::FILTER_POINT, 1);
     } else {
         if ($image_information[2] == 2 && is_callable('ImageCreateTrueColor') && ($thumbnail = ImageCreateTrueColor($thumbnail_width, $thumbnail_height))) {
             ImageCopyResampled($thumbnail, $image, 0, 0, 0, 0, $thumbnail_width, $thumbnail_height, $width, $height);
         }
         if (!$thumbnail && is_callable('ImageCreate') && ($thumbnail = ImageCreate($thumbnail_width, $thumbnail_height))) {
             ImageCopyResized($thumbnail, $image, 0, 0, 0, 0, $thumbnail_width, $thumbnail_height, $width, $height);
         }
     }
     // sanity check
     if (!$thumbnail) {
         if ($verbose) {
             Logger::error(sprintf(i18n::s('Impossible to skrink image %s'), $file_name));
         }
         return FALSE;
     }
     // save the thumbnail in the file system
     $result = FALSE;
     if (Image::use_magic()) {
         $result = $image->writeImage($target);
     } else {
         if ($image_information[2] == 1 && is_callable('ImageGIF')) {
             ImageGIF($thumbnail, $target);
//.........这里部分代码省略.........
开发者ID:rair,项目名称:yacs,代码行数:101,代码来源:image.php

示例11: upFile

 /**
  * 上传文件的主处理方法
  * @return mixed
  */
 private function upFile()
 {
     $file = $this->file = $_FILES[$this->fileField];
     if (!$file) {
         $this->stateInfo = $this->getStateInfo("ERROR_FILE_NOT_FOUND");
         return;
     }
     if ($this->file['error']) {
         $this->stateInfo = $this->getStateInfo($file['error']);
         return;
     } else {
         if (!file_exists($file['tmp_name'])) {
             $this->stateInfo = $this->getStateInfo("ERROR_TMP_FILE_NOT_FOUND");
             return;
         } else {
             if (!is_uploaded_file($file['tmp_name'])) {
                 $this->stateInfo = $this->getStateInfo("ERROR_TMPFILE");
                 return;
             }
         }
     }
     $this->oriName = $file['name'];
     $this->fileSize = $file['size'];
     $this->fileType = $this->getFileExt();
     $this->fullName = $this->getFullName();
     $this->filePath = $this->getFilePath();
     $this->fileName = $this->getFileName();
     $dirname = dirname($this->filePath);
     //检查文件大小是否超出限制
     if (!$this->checkSize()) {
         $this->stateInfo = $this->getStateInfo("ERROR_SIZE_EXCEED");
         return;
     }
     //检查是否不允许的文件格式
     if (!$this->checkType()) {
         $this->stateInfo = $this->getStateInfo("ERROR_TYPE_NOT_ALLOWED");
         return;
     }
     //创建目录失败
     if (!file_exists($dirname) && !mkdir($dirname, 0777, TRUE)) {
         $this->stateInfo = $this->getStateInfo("ERROR_CREATE_DIR");
         return;
     } else {
         if (!is_writeable($dirname)) {
             $this->stateInfo = $this->getStateInfo("ERROR_DIR_NOT_WRITEABLE");
             return;
         }
     }
     //移动文件
     if (!(move_uploaded_file($file["tmp_name"], $this->filePath) && file_exists($this->filePath))) {
         //移动失败
         $this->stateInfo = $this->getStateInfo("ERROR_FILE_MOVE");
     } else {
         //移动成功
         $this->stateInfo = $this->stateMap[0];
         //加水印
         require_once "Image.class.php";
         $image = new Image();
         $image->open($this->filePath)->thumb('480', '5000', Image::IMAGE_THUMB_SCALE)->water('./logo.png', Image::IMAGE_WATER_SOUTHEAST, 100)->save($this->filePath);
     }
 }
开发者ID:anLl,项目名称:ybirds,代码行数:65,代码来源:Uploader.class.php

示例12: explode

//echo $caminho; exit;
$div1 = explode(".", $caminho);
$new = $div1[0];
for ($i = 1; $i < count($div1) - 1; $i++) {
    $new .= "." . $div1[$i];
}
$nome = basename($caminho);
$nome = str_replace("." . $div1[count($div1) - 1], "", $nome);
$div2 = explode('-', $new);
$width = $div2[count($div2) - 2];
$height = $div2[count($div2) - 1];
$caminho = str_replace("size-" . $width . "-" . $height, "", $caminho);
$arq = new Arquivos(str_replace("", '', Sistema::$caminhoDiretorio) . urldecode($caminho));
header('Expires: 0');
header('Pragma: no-cache');
if (strtoupper($arq->extensao) == "JPEG" || strtoupper($arq->extensao) == "JPG" || strtoupper($arq->extensao) == "PNG" || strtoupper($arq->extensao) == "GIF" || strtoupper($arq->extensao) == "BMP") {
    header("Content-type: image/" . $arq->extensao);
    $img = new Image($arq);
    $img->open();
    if (!empty($width) && !empty($height)) {
        $img->redimensionar($width, $height);
        $img->saveImage(dirname(substr(str_replace("", '', Sistema::$caminhoDiretorio), 0, -1) . urldecode($caminho)), urldecode($nome));
    }
    $img->getImage();
} else {
    header("Content-Type: application/" . $arq->extensao);
    header('Content-disposition: attachment; filename="' . $arq->getNome() . '";');
    $len = filesize($arq->url);
    header("Content-Length: " . $len . ";\n");
    echo $arq->arquivo;
}
开发者ID:jhonnybail,项目名称:marktronic,代码行数:31,代码来源:openImage.php

示例13: 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 File|string $obj
  * @param int $maxWidth
  * @param int $maxHeight
  * @param bool $crop
  * @return \stdClass Object that has the following properties: src, width, height
  */
 public function getThumbnail($obj, $maxWidth, $maxHeight, $crop = false)
 {
     $storage = $this->getStorageLocation();
     $filesystem = $storage->getFileSystemObject();
     $configuration = $storage->getConfigurationObject();
     $fh = \Core::make('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);
     }
     $abspath = '/cache/' . $filename;
     if (!$filesystem->has($abspath)) {
         if ($obj instanceof File && $fr->exists()) {
             $image = \Image::load($fr->read());
         } else {
             $image = \Image::open($obj);
         }
         // create image there
         $this->create($image, $abspath, $maxWidth, $maxHeight, $crop);
     }
     $src = $configuration->getPublicURLToFile($abspath);
     $thumb = new \stdClass();
     $thumb->src = $src;
     //this is terrible
     try {
         //try and get it locally, otherwise use http
         $dimensions = getimagesize($abspath);
     } catch (\Exception $e) {
         //$dimensions = getimagesize($src);
     }
     $thumb->width = $dimensions[0];
     $thumb->height = $dimensions[1];
     return $thumb;
 }
开发者ID:ppiedaderawnet,项目名称:concrete5,代码行数:52,代码来源:BasicThumbnailer.php

示例14: imageManipulationSync

 /**
  * @param Request $request
  */
 protected function imageManipulationSync(Request $request)
 {
     $file = $request->file('image');
     $nomeFoto = $request->get('foto');
     $file->move("foto/real/", $nomeFoto);
     $urlFilePath = 'foto/real/' . $nomeFoto;
     $thumbnail = \Image::open($urlFilePath)->thumbnail(new \Imagine\Image\Box(90, 70));
     $thumbnail->save('foto/thumbnail/' . $nomeFoto);
     $thumbnail = \Image::open($urlFilePath)->thumbnail(new \Imagine\Image\Box(400, 300));
     $thumbnail->save('foto/medium/' . $nomeFoto);
 }
开发者ID:edyonil,项目名称:lumemPaPComJesus,代码行数:14,代码来源:Church.php

示例15: process_image

 public static function process_image($extend)
 {
     $file = Arr::get(static::files(), $extend->key);
     if ($file and $file['error'] === UPLOAD_ERR_OK) {
         $name = basename($file['name']);
         $ext = pathinfo($file['name'], PATHINFO_EXTENSION);
         if ($filepath = static::upload($file)) {
             $filename = basename($filepath);
             // resize image
             if (isset($extend->attributes->size->width) and isset($extend->attributes->size->height)) {
                 $image = Image::open($filepath);
                 $width = intval($extend->attributes->size->width);
                 $height = intval($extend->attributes->size->height);
                 // resize larger images
                 if ($width and $height and ($image->width() > $width or $image->height() > $height)) {
                     $image->resize($width, $height);
                     $image->output($ext, $filepath);
                 }
             }
             return Json::encode(compact('name', 'filename'));
         }
     }
 }
开发者ID:svita-cz,项目名称:web,代码行数:23,代码来源:extend.php


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