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


PHP File::createFromFile方法代码示例

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


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

示例1: post

 function post()
 {
     if (\Idno\Core\Idno::site()->session()->isLoggedOn()) {
         if (!empty($_FILES['file']['tmp_name'])) {
             if (!\Idno\Core\Idno::site()->triggerEvent("file/upload", [], true)) {
                 exit;
             }
             if (\Idno\Entities\File::isImage($_FILES['file']['tmp_name'])) {
                 $return = false;
                 $file = false;
                 if ($file = \Idno\Entities\File::createThumbnailFromFile($_FILES['file']['tmp_name'], $_FILES['file']['name'], 1024)) {
                     $return = true;
                     $returnfile = new \stdClass();
                     $returnfile->file = ['_id' => $file];
                     $file = $returnfile;
                 } else {
                     if ($file = \Idno\Entities\File::createFromFile($_FILES['file']['tmp_name'], $_FILES['file']['name'], $_FILES['file']['type'], true)) {
                         $return = true;
                     }
                 }
                 if ($return) {
                     $t = \Idno\Core\Idno::site()->template();
                     $t->file = $file;
                     echo $t->draw('file/picker/donejs');
                     exit;
                 }
             } else {
                 Idno::site()->session()->addErrorMessage("You can only upload images.");
             }
         }
         $this->forward($_SERVER['HTTP_REDIRECT']);
     }
 }
开发者ID:knownunknowns,项目名称:Known,代码行数:33,代码来源:Picker.php

示例2: saveDataFromInput

 /**
  * Saves changes to this object based on user input
  * @return bool
  */
 function saveDataFromInput()
 {
     if (empty($this->_id)) {
         $new = true;
     } else {
         $new = false;
     }
     $this->title = \Idno\Core\site()->currentPage()->getInput('title');
     $this->body = \Idno\Core\site()->currentPage()->getInput('body');
     $this->tags = \Idno\Core\site()->currentPage()->getInput('tags');
     $this->setAccess('PUBLIC');
     if ($time = \Idno\Core\site()->currentPage()->getInput('created')) {
         if ($time = strtotime($time)) {
             $this->created = $time;
         }
     }
     // Get photo
     if ($new) {
         if (!empty($_FILES['photo']['tmp_name'])) {
             if (\Idno\Entities\File::isImage($_FILES['photo']['tmp_name'])) {
                 if ($photo = \Idno\Entities\File::createFromFile($_FILES['photo']['tmp_name'], $_FILES['photo']['name'], $_FILES['photo']['type'], true)) {
                     $this->attachFile($photo);
                     // Now get some smaller thumbnails, with the option to override sizes
                     $sizes = \Idno\Core\site()->events()->dispatch('photo/thumbnail/getsizes', new \Idno\Core\Event(array('sizes' => ['large' => 800, 'medium' => 400, 'small' => 200])));
                     foreach ($sizes->data()['sizes'] as $label => $size) {
                         $filename = $_FILES['photo']['name'];
                         // Experiment: let's not save thumbnails for GIFs, in order to enable animated GIF posting.
                         if ($_FILES['photo']['type'] != 'image/gif') {
                             if ($thumbnail = \Idno\Entities\File::createThumbnailFromFile($_FILES['photo']['tmp_name'], "{$filename}_{$label}", $size)) {
                                 $varname = "thumbnail_{$label}";
                                 $this->{$varname} = \Idno\Core\site()->config()->url . 'file/' . $thumbnail;
                                 $varname = "thumbnail_{$label}_id";
                                 $this->{$varname} = substr($thumbnail, 0, strpos($thumbnail, '/'));
                             }
                         }
                     }
                 } else {
                     \Idno\Core\site()->session()->addMessage('Image wasn\'t attached.');
                 }
             } else {
                 \Idno\Core\site()->session()->addMessage('This doesn\'t seem to be an image ..');
             }
         } else {
             \Idno\Core\site()->session()->addMessage('We couldn\'t access your image. Please try again.');
             return false;
         }
     }
     if ($this->save()) {
         if ($new) {
             $this->addToFeed();
         }
         // Add it to the Activity Streams feed
         \Idno\Core\Webmention::pingMentions($this->getURL(), \Idno\Core\site()->template()->parseURLs($this->getTitle() . ' ' . $this->getDescription()));
         return true;
     } else {
         return false;
     }
 }
开发者ID:avewrigley,项目名称:idno,代码行数:62,代码来源:Photo.php

示例3: postContent

 function postContent()
 {
     $this->adminGatekeeper();
     // Flag that a site export has been requested
     \Idno\Core\Idno::site()->config()->export_last_requested = time();
     \Idno\Core\Idno::site()->config()->export_in_progress = 1;
     \Idno\Core\Idno::site()->config()->save();
     $this->forward(\Idno\Core\Idno::site()->config()->getDisplayURL() . 'admin/export/', false);
     ignore_user_abort(true);
     // This is dangerous, but we need export to continue
     session_write_close();
     header('Connection: close');
     header('Content-length: ' . (string) ob_get_length());
     @ob_end_flush();
     // Return output to the browser
     @ob_end_clean();
     @flush();
     sleep(10);
     // Pause
     set_time_limit(0);
     // Eliminate time limit - this could take a while
     // Remove the previous export file
     if (!empty(\Idno\Core\Idno::site()->config()->export_file_id)) {
         if ($file = File::getByID(\Idno\Core\Idno::site()->config()->export_file_id)) {
             $file->remove();
             \Idno\Core\Idno::site()->config()->export_file_id = false;
             \Idno\Core\Idno::site()->config()->export_filename = false;
             \Idno\Core\Idno::site()->config()->save();
         }
     }
     if ($path = Migration::createCompressedArchive()) {
         $filename = \Idno\Core\Idno::site()->config()->host . '.zip';
         /*                    header('Content-disposition: attachment;filename=' . $filename);
                               if ($fp = fopen($path, 'r')) {
                                   while ($content = fread($fp, 4096)) {
                                       echo $content;
                                   }
                               }
                               fclose($fp);*/
         if ($file = File::createFromFile($path, $filename)) {
             @unlink($path);
             \Idno\Core\Idno::site()->config()->export_filename = $filename;
             \Idno\Core\Idno::site()->config()->export_file_id = $file;
             \Idno\Core\Idno::site()->config()->export_in_progress = 0;
             \Idno\Core\Idno::site()->config()->save();
             $mail = new Email();
             $mail->setHTMLBodyFromTemplate('admin/export');
             $mail->setTextBodyFromTemplate('admin/export');
             $mail->addTo(\Idno\Core\Idno::site()->session()->currentUser()->email);
             $mail->setSubject("Your data export is ready");
             $mail->send();
         }
         exit;
     }
 }
开发者ID:sintoris,项目名称:Known,代码行数:55,代码来源:Generate.php

示例4: post

 function post()
 {
     if (\Idno\Core\site()->session()->isLoggedOn()) {
         if (!empty($_FILES['file']['tmp_name'])) {
             if ($file = \Idno\Entities\File::createFromFile($_FILES['file']['tmp_name'], $_FILES['file']['name'], $_FILES['file']['type'], true)) {
                 echo json_encode(\Idno\Core\site()->config()->url . 'file/' . $file->file['_id']);
                 error_log(\Idno\Core\site()->config()->url . 'file/' . $file->file['_id']);
             }
         }
     }
 }
开发者ID:avewrigley,项目名称:idno,代码行数:11,代码来源:Upload.php

示例5: post

 function post()
 {
     if (\Idno\Core\site()->session()->isLoggedOn()) {
         if (!empty($_FILES['file']['tmp_name'])) {
             if (!\Idno\Core\site()->triggerEvent("file/upload", [], true)) {
                 exit;
             }
             if ($file = \Idno\Entities\File::createFromFile($_FILES['file']['tmp_name'], $_FILES['file']['name'], $_FILES['file']['type'], true, true)) {
                 echo json_encode(\Idno\Core\site()->config()->url . 'file/' . $file->file['_id']);
             }
         }
     }
 }
开发者ID:hank,项目名称:Known,代码行数:13,代码来源:Upload.php

示例6: postContent

 function postContent()
 {
     $this->adminGatekeeper();
     // Admins only
     if ($profile_user = $this->getInput('profile_user')) {
         \Idno\Core\Idno::site()->config->config['cherwell']['profile_user'] = $profile_user;
     }
     if (!empty($_FILES['background']) && $this->getInput('action') != 'clear') {
         if (in_array($_FILES['background']['type'], array('image/png', 'image/jpg', 'image/jpeg', 'image/gif'))) {
             if (getimagesize($_FILES['background']['tmp_name'])) {
                 if ($background = \Idno\Entities\File::createFromFile($_FILES['background']['tmp_name'], $_FILES['background']['name'])) {
                     // Remove previous bg
                     if (!empty(\Idno\Core\Idno::site()->config()->cherwell['bg_id'])) {
                         if ($file = File::getByID(\Idno\Core\Idno::site()->config()->cherwell['bg_id'])) {
                             if (is_callable([$file, 'delete'])) {
                                 // TODO: really need some abstraction here.
                                 $file->delete();
                             } else {
                                 if (is_callable([$file, 'remove'])) {
                                     $file->remove();
                                 }
                             }
                         }
                     }
                     \Idno\Core\Idno::site()->config->config['cherwell']['bg_id'] = $background;
                     $background = \Idno\Core\Idno::site()->config()->getDisplayURL() . 'file/' . $background;
                     \Idno\Core\Idno::site()->config->config['cherwell']['bg'] = $background;
                 }
             }
         }
     } else {
         // Remove previous bg
         if (!empty(\Idno\Core\Idno::site()->config()->cherwell['bg_id'])) {
             if ($file = File::getByID(\Idno\Core\Idno::site()->config()->cherwell['bg_id'])) {
                 if (is_callable([$file, 'delete'])) {
                     $file->delete();
                 } else {
                     if (is_callable([$file, 'remove'])) {
                         $file->remove();
                     }
                 }
             }
         }
         \Idno\Core\Idno::site()->config->cherwell = [];
     }
     \Idno\Core\Idno::site()->config->save();
     $this->forward(\Idno\Core\Idno::site()->config()->getDisplayURL() . 'admin/cherwell/');
 }
开发者ID:sintoris,项目名称:Known,代码行数:48,代码来源:Admin.php

示例7: post

 function post()
 {
     if (\Idno\Core\site()->session()->isLoggedOn()) {
         if (!empty($_FILES['file']['tmp_name'])) {
             if (!\Idno\Core\site()->triggerEvent("file/upload", [], true)) {
                 exit;
             }
             if ($file = \Idno\Entities\File::createFromFile($_FILES['file']['tmp_name'], $_FILES['file']['name'], $_FILES['file']['type'], true)) {
                 $t = \Idno\Core\site()->template();
                 $t->file = $file;
                 echo $t->draw('file/picker/donejs');
                 exit;
             }
         }
     }
 }
开发者ID:hank,项目名称:Known,代码行数:16,代码来源:Picker.php

示例8: saveDataFromInput

 function saveDataFromInput()
 {
     if (empty($this->_id)) {
         $new = true;
     } else {
         $new = false;
     }
     if ($new) {
         if (!\Idno\Core\Idno::site()->triggerEvent("file/upload", [], true)) {
             return false;
         }
     }
     $body = \Idno\Core\Idno::site()->currentPage()->getInput('body');
     if (!empty($_FILES['comic']['tmp_name']) || !empty($this->_id)) {
         $this->body = $body;
         $this->title = \Idno\Core\Idno::site()->currentPage()->getInput('title');
         $this->description = \Idno\Core\Idno::site()->currentPage()->getInput('description');
         if ($time = \Idno\Core\Idno::site()->currentPage()->getInput('created')) {
             if ($time = strtotime($time)) {
                 $this->created = $time;
             }
         }
         if (!empty($_FILES['comic']['tmp_name'])) {
             if (\Idno\Entities\File::isImage($_FILES['comic']['tmp_name'])) {
                 if ($size = getimagesize($_FILES['comic']['tmp_name'])) {
                     $this->width = $size[0];
                     $this->height = $size[1];
                 }
                 if ($comic = \Idno\Entities\File::createFromFile($_FILES['comic']['tmp_name'], $_FILES['comic']['name'], $_FILES['comic']['type'], true)) {
                     $this->attachFile($comic);
                 }
             }
         }
         $this->setAccess(\Idno\Core\Idno::site()->currentPage()->getInput('access', 'PUBLIC'));
         if ($this->save($new)) {
             if ($this->getAccess() == 'PUBLIC') {
                 \Idno\Core\Webmention::pingMentions($this->getURL(), \Idno\Core\Idno::site()->template()->parseURLs($this->getDescription()));
             }
             return true;
         }
     } else {
         \Idno\Core\Idno::site()->session()->addErrorMessage('You can\'t save an empty comic.');
     }
     return false;
 }
开发者ID:sintoris,项目名称:Known,代码行数:45,代码来源:Comic.php

示例9: saveDataFromInput

 /**
  * Saves changes to this object based on user input
  * @return bool
  */
 function saveDataFromInput()
 {
     if (empty($this->_id)) {
         $new = true;
     } else {
         $new = false;
     }
     $this->title = \Idno\Core\site()->currentPage()->getInput('title');
     $this->body = \Idno\Core\site()->currentPage()->getInput('body');
     $this->setAccess('PUBLIC');
     // Get photo
     if ($new) {
         if (!empty($_FILES['photo']['tmp_name'])) {
             if (\Idno\Entities\File::isImage($_FILES['photo']['tmp_name'])) {
                 if ($photo = \Idno\Entities\File::createFromFile($_FILES['photo']['tmp_name'], $_FILES['photo']['name'], $_FILES['photo']['type'], true)) {
                     $this->attachFile($photo);
                     if ($thumbnail = \Idno\Entities\File::createThumbnailFromFile($_FILES['photo']['tmp_name'], $_FILES['photo']['name'])) {
                         $this->thumbnail = \Idno\Core\site()->config()->url . 'file/' . $thumbnail;
                         $this->thumbnail_id = substr($thumbnail, 0, strpos($thumbnail, '/'));
                     }
                 } else {
                     \Idno\Core\site()->session()->addMessage('Image wasn\'t attached.');
                 }
             } else {
                 \Idno\Core\site()->session()->addMessage('This doesn\'t seem to be an image ..');
             }
         } else {
             \Idno\Core\site()->session()->addMessage('We couldn\'t access your image. Please try again.');
             return false;
         }
     }
     if ($this->save()) {
         if ($new) {
             $this->addToFeed();
         }
         // Add it to the Activity Streams feed
         \Idno\Core\Webmention::pingMentions($this->getURL(), \Idno\Core\site()->template()->parseURLs($this->getDescription()));
         \Idno\Core\site()->session()->addMessage('Your photo was successfully saved.');
         return true;
     } else {
         return false;
     }
 }
开发者ID:phpsource,项目名称:idno,代码行数:47,代码来源:Photo.php

示例10: saveDataFromInput

 function saveDataFromInput()
 {
     if (empty($this->_id)) {
         $new = true;
     } else {
         $new = false;
     }
     $body = \Idno\Core\site()->currentPage()->getInput('body');
     if (!empty($_FILES['comic']['tmp_name']) || !empty($this->_id)) {
         $this->body = $body;
         $this->title = \Idno\Core\site()->currentPage()->getInput('title');
         $this->description = \Idno\Core\site()->currentPage()->getInput('description');
         if ($time = \Idno\Core\site()->currentPage()->getInput('created')) {
             if ($time = strtotime($time)) {
                 $this->created = $time;
             }
         }
         if (!empty($_FILES['comic']['tmp_name'])) {
             if (\Idno\Entities\File::isImage($_FILES['comic']['tmp_name'])) {
                 if ($size = getimagesize($_FILES['comic']['tmp_name'])) {
                     $this->width = $size[0];
                     $this->height = $size[1];
                 }
                 if ($comic = \Idno\Entities\File::createFromFile($_FILES['comic']['tmp_name'], $_FILES['comic']['name'], $_FILES['comic']['type'], true)) {
                     $this->attachFile($comic);
                 }
             }
         }
         $this->setAccess('PUBLIC');
         if ($this->save()) {
             if ($new) {
                 // Add it to the Activity Streams feed
                 $this->addToFeed();
             }
             \Idno\Core\Webmention::pingMentions($this->getURL(), \Idno\Core\site()->template()->parseURLs($this->getDescription()));
             return true;
         }
     } else {
         \Idno\Core\site()->session()->addMessage('You can\'t save an empty comic.');
     }
     return false;
 }
开发者ID:avewrigley,项目名称:idno,代码行数:42,代码来源:Comic.php

示例11: postContent

 function postContent()
 {
     $this->gatekeeper();
     // Logged-in only please
     $user = \Idno\Core\site()->session()->currentUser();
     $name = $this->getInput('name');
     //$handle = $this->getInput('handle');
     $email = $this->getInput('email');
     $password = $this->getInput('password');
     $password2 = $this->getInput('password2');
     if (!empty($name)) {
         $user->setTitle($name);
     }
     if (!empty($email) && $email != $user->email && filter_var($email, FILTER_VALIDATE_EMAIL)) {
         if (!\Idno\Entities\User::getByEmail($email)) {
             $user->email = $email;
         } else {
             \Idno\Core\site()->session()->addMessage('Someone is already using ' . $email . ' as their email address.', 'alert-error');
         }
     }
     if (!empty($password) && $password == $password2) {
         $user->setPassword($password);
     }
     if (!empty($_FILES['avatar'])) {
         if (in_array($_FILES['avatar']['type'], array('image/png', 'image/jpg', 'image/jpeg', 'image/gif'))) {
             if (getimagesize($_FILES['avatar']['tmp_name'])) {
                 if ($icon = \Idno\Entities\File::createThumbnailFromFile($_FILES['avatar']['tmp_name'], $_FILES['avatar']['name'], 300)) {
                     $user->icon = (string) $icon;
                 } else {
                     if ($icon = \Idno\Entities\File::createFromFile($_FILES['avatar']['tmp_name'], $_FILES['avatar']['name'])) {
                         $user->icon = (string) $icon;
                     }
                 }
             }
         }
     }
     if ($user->save()) {
         \Idno\Core\site()->session()->addMessage("Your details were saved.");
     }
     $this->forward($_SERVER['HTTP_REFERER']);
 }
开发者ID:phpsource,项目名称:idno,代码行数:41,代码来源:Settings.php

示例12: saveDataFromInput

 /**
  * Saves changes to this object based on user input
  * @return bool
  */
 function saveDataFromInput()
 {
     if (empty($this->_id)) {
         $new = true;
     } else {
         $new = false;
     }
     $this->title = \Idno\Core\site()->currentPage()->getInput('title');
     $this->body = \Idno\Core\site()->currentPage()->getInput('body');
     $this->setAccess('PUBLIC');
     // Get video
     if ($new) {
         if (!empty($_FILES['video']['tmp_name'])) {
             if (true) {
                 if ($video = \Idno\Entities\File::createFromFile($_FILES['video']['tmp_name'], $_FILES['video']['name'], $_FILES['video']['type'], true)) {
                     $this->attachFile($video);
                 } else {
                     \Idno\Core\site()->session()->addMessage('Video wasn\'t attached.');
                 }
             } else {
                 \Idno\Core\site()->session()->addMessage('This doesn\'t seem to be a video ..');
             }
         } else {
             \Idno\Core\site()->session()->addMessage('We couldn\'t access your video. Please try again.');
             return false;
         }
     }
     if ($this->save()) {
         if ($new) {
             $this->addToFeed();
         }
         // Add it to the Activity Streams feed
         \Idno\Core\Webmention::pingMentions($this->getURL(), \Idno\Core\site()->template()->parseURLs($this->getDescription()));
         \Idno\Core\site()->session()->addMessage('Your video was successfully saved.');
         return true;
     } else {
         return false;
     }
 }
开发者ID:phpsource,项目名称:idno,代码行数:43,代码来源:Video.php

示例13: importImagesFromBodyHTML

 static function importImagesFromBodyHTML($body, $src_url)
 {
     $doc = new \DOMDocument();
     if (@$doc->loadHTML($body)) {
         if ($images = $doc->getElementsByTagName('img')) {
             foreach ($images as $image) {
                 $src = $image->getAttribute('src');
                 if (substr_count($src, $src_url)) {
                     $dir = site()->config()->getTempDir();
                     $name = md5($src);
                     $newname = $dir . $name . basename($src);
                     if (@file_put_contents($newname, fopen($src, 'r'))) {
                         switch (strtolower(pathinfo($src, PATHINFO_EXTENSION))) {
                             case 'jpg':
                             case 'jpeg':
                                 $mime = 'image/jpg';
                                 break;
                             case 'gif':
                                 $mime = 'image/gif';
                                 break;
                             case 'png':
                                 $mime = 'image/png';
                                 break;
                             default:
                                 $mime = 'application/octet-stream';
                         }
                         if ($file = File::createFromFile($newname, basename($src), $mime, true)) {
                             $newsrc = \Idno\Core\site()->config()->getURL() . 'file/' . $file->file['_id'];
                             $body = str_replace($src, $newsrc, $body);
                             @unlink($newname);
                         }
                     }
                 }
             }
         }
     }
 }
开发者ID:hank,项目名称:Known,代码行数:37,代码来源:Migration.php

示例14: createThumbnailFromFile

 /**
  * Given a path to an image on disk, generates and saves a thumbnail with maximum dimension $max_dimension.
  * @param string $file_path Path to the file.
  * @param string $filename Filename that the file should have on download.
  * @param int $max_dimension The maximum number of pixels the thumbnail image should be along its longest side.
  * @param bool $square If this is set to true, the thumbnail will be made square.
  * @return bool|id
  */
 public static function createThumbnailFromFile($file_path, $filename, $max_dimension = 800, $square = false)
 {
     $thumbnail = false;
     if ($photo_information = getimagesize($file_path)) {
         if ($photo_information[0] > $max_dimension || $photo_information[1] > $max_dimension) {
             switch ($photo_information['mime']) {
                 case 'image/jpeg':
                     $image = imagecreatefromjpeg($file_path);
                     break;
                 case 'image/png':
                     $image = imagecreatefrompng($file_path);
                     $background = imagecolorallocatealpha($image, 0, 0, 0, 127);
                     imagecolortransparent($image, $background);
                     break;
                 case 'image/gif':
                     $image = imagecreatefromgif($file_path);
                     $background = imagecolorallocatealpha($image, 0, 0, 0, 127);
                     imagecolortransparent($image, $background);
                     break;
             }
             if (!empty($image)) {
                 if ($photo_information[0] > $photo_information[1]) {
                     $width = $max_dimension;
                     $height = round($photo_information[1] * ($max_dimension / $photo_information[0]));
                 } else {
                     $height = $max_dimension;
                     $width = round($photo_information[0] * ($max_dimension / $photo_information[1]));
                 }
                 if ($square) {
                     if ($width > $height) {
                         $new_height = $max_dimension;
                         $new_width = $max_dimension;
                         $original_height = $photo_information[1];
                         $original_width = $photo_information[1];
                         $offset_x = round(($photo_information[0] - $photo_information[1]) / 2);
                         $offset_y = 0;
                     } else {
                         $new_height = $max_dimension;
                         $new_width = $max_dimension;
                         $original_height = $photo_information[0];
                         $original_width = $photo_information[0];
                         $offset_x = 0;
                         $offset_y = round(($photo_information[1] - $photo_information[0]) / 2);
                     }
                 } else {
                     $new_height = $height;
                     $new_width = $width;
                     $original_height = $photo_information[1];
                     $original_width = $photo_information[0];
                     $offset_x = 0;
                     $offset_y = 0;
                 }
                 $image_copy = imagecreatetruecolor($new_width, $new_height);
                 imagealphablending($image_copy, false);
                 imagesavealpha($image_copy, true);
                 imagecopyresampled($image_copy, $image, 0, 0, $offset_x, $offset_y, $new_width, $new_height, $original_width, $original_height);
                 $tmp_dir = dirname($file_path);
                 switch ($photo_information['mime']) {
                     case 'image/jpeg':
                         imagejpeg($image_copy, $tmp_dir . '/' . $filename . '.jpg', 85);
                         $thumbnail = \Idno\Entities\File::createFromFile($tmp_dir . '/' . $filename . '.jpg', "thumb_{$max_dimension}.jpg", 'image/jpeg') . '/thumb.jpg';
                         @unlink($tmp_dir . '/' . $filename . '.jpg');
                         break;
                     case 'image/png':
                         imagepng($image_copy, $tmp_dir . '/' . $filename . '.png');
                         $thumbnail = \Idno\Entities\File::createFromFile($tmp_dir . '/' . $filename . '.png', "thumb_{$max_dimension}.png", 'image/png') . '/thumb.png';
                         @unlink($tmp_dir . '/' . $filename . '.png');
                         break;
                     case 'image/gif':
                         imagegif($image_copy, $tmp_dir . '/' . $filename . '.gif');
                         $thumbnail = \Idno\Entities\File::createFromFile($tmp_dir . '/' . $filename . '.gif', "thumb_{$max_dimension}.gif", 'image/gif') . '/thumb.gif';
                         @unlink($tmp_dir . '/' . $filename . '.gif');
                         break;
                 }
             }
         } else {
         }
         return $thumbnail;
     }
     return false;
 }
开发者ID:sensiblemn,项目名称:Known,代码行数:89,代码来源:File.php

示例15: createThumbnailFromFile

 /**
  * Given a path to an image on disk, generates and saves a thumbnail with maximum dimension $max_dimension.
  * @param string $file_path Path to the file.
  * @param string $filename Filename that the file should have on download.
  * @param int $max_dimension The maximum number of pixels the thumbnail image should be along its longest side.
  * @return bool|MongoID
  */
 public static function createThumbnailFromFile($file_path, $filename, $max_dimension = 800)
 {
     $thumbnail = false;
     if ($photo_information = getimagesize($file_path)) {
         if ($photo_information[0] > $max_dimension || $photo_information[1] > $max_dimension) {
             switch ($photo_information['mime']) {
                 case 'image/jpeg':
                     $image = imagecreatefromjpeg($file_path);
                     break;
                 case 'image/png':
                     $image = imagecreatefrompng($file_path);
                     break;
                 case 'image/gif':
                     $image = imagecreatefromgif($file_path);
                     break;
             }
             if (!empty($image)) {
                 if ($photo_information[0] > $photo_information[1]) {
                     $width = $max_dimension;
                     $height = round($photo_information[1] * ($max_dimension / $photo_information[0]));
                 } else {
                     $height = $max_dimension;
                     $width = round($photo_information[0] * ($max_dimension / $photo_information[1]));
                 }
                 $image_copy = imagecreatetruecolor($width, $height);
                 imagecopyresampled($image_copy, $image, 0, 0, 0, 0, $width, $height, $photo_information[0], $photo_information[1]);
                 if (is_callable('exif_read_data')) {
                     $exif = exif_read_data($file_path);
                     if (!empty($exif['Orientation'])) {
                         switch ($exif['Orientation']) {
                             case 8:
                                 $image_copy = imagerotate($image_copy, 90, 0);
                                 break;
                             case 3:
                                 $image_copy = imagerotate($image_copy, 180, 0);
                                 break;
                             case 6:
                                 $image_copy = imagerotate($image_copy, -90, 0);
                                 break;
                         }
                     }
                 }
                 $tmp_dir = dirname($file_path);
                 switch ($photo_information['mime']) {
                     case 'image/jpeg':
                         imagejpeg($image_copy, $tmp_dir . '/' . $filename . '.jpg');
                         $thumbnail = \Idno\Entities\File::createFromFile($tmp_dir . '/' . $filename . '.jpg', 'thumb.jpg', 'image/jpeg') . '/thumb.jpg';
                         @unlink($tmp_dir . '/' . $filename . '.jpg');
                         break;
                     case 'image/png':
                         imagepng($image_copy, $tmp_dir . '/' . $filename . '.png');
                         $thumbnail = \Idno\Entities\File::createFromFile($tmp_dir . '/' . $filename . '.png', 'thumb.png', 'image/png') . '/thumb.png';
                         @unlink($tmp_dir . '/' . $filename . '.png');
                         break;
                     case 'image/gif':
                         imagegif($image_copy, $tmp_dir . '/' . $filename . '.gif');
                         $thumbnail = \Idno\Entities\File::createFromFile($tmp_dir . '/' . $filename . '.gif', 'thumb.gif', 'image/gif') . '/thumb.gif';
                         @unlink($tmp_dir . '/' . $filename . '.gif');
                         break;
                 }
             }
         } else {
         }
         return $thumbnail;
     }
 }
开发者ID:phpsource,项目名称:idno,代码行数:73,代码来源:File.php


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