コード例 #1
0
    }
    if (!is_dir($argv[1])) {
        exit($argv[1] . "' is not a directory\n");
    }
} else {
    die;
}
require 'SimpleImage.php';
$img = new SimpleImage();
$path_thumbs = $reldir . 'thumbs/';
$path_imgs = $reldir;
if (!is_dir($path_thumbs)) {
    mkdir($path_thumbs);
}
$allowed = array('gif', 'jpg', 'jpeg', 'png', 'ttf');
$dir_imgs = new \DirectoryIterator($path_imgs);
foreach ($dir_imgs as $fileinfo) {
    if (!$fileinfo->isDot() && $fileinfo->isFile() && in_array($fileinfo->getExtension(), $allowed)) {
        $name = $fileinfo->getFilename();
        $pathname = $path_imgs . $fileinfo->getFilename();
        echo $name . "\n";
        try {
            $img->load($pathname)->fit_to_height(300)->save($path_thumbs . $name);
        } catch (Exception $e) {
            echo '<span style="color: red;">' . $e->getMessage() . '</span>';
        }
    }
}
// Local Variables:
// firestarter: "gist -u a80d7b60361c786afeba %p"
// End:
コード例 #2
0
ファイル: index.php プロジェクト: Malagasy/arpt-wp-plugs
namespace abeautifulsite;

use Exception;
require '../src/abeautifulsite/SimpleImage.php';
if (!is_dir('processed/')) {
    mkdir('processed/');
}
try {
    //
    // WARNING: This will create a lot of images in the /processed folder
    //
    $img = new SimpleImage();
    // Create from scratch
    $img->create(200, 100, '#08c')->save('processed/create-from-scratch.png');
    // Convert to GIF
    $img->load('butterfly.jpg')->save('processed/butterfly-convert-to-gif.gif');
    // Strip exif data (just load and save)
    $img->load('butterfly.jpg')->save('processed/butterfly-strip-exif.jpg');
    // Flip horizontal
    $img->load('butterfly.jpg')->flip('x')->save('processed/butterfly-flip-horizontal.jpg');
    // Flip vertical
    $img->load('butterfly.jpg')->flip('y')->save('processed/butterfly-flip-vertical.jpg');
    // Flip both
    $img->load('butterfly.jpg')->flip('x')->flip('y')->save('processed/butterfly-flip-both.jpg');
    // Rotate 90
    $img->load('butterfly.jpg')->rotate(90)->save('processed/butterfly-rotate-90.jpg');
    // Auto-orient
    $img->load('butterfly.jpg')->auto_orient()->save('processed/butterfly-auto-orient.jpg');
    // Resize
    $img->load('butterfly.jpg')->resize(320, 239)->save('processed/butterfly-resize.jpg');
    // Thumbnail
コード例 #3
0
ファイル: FtpManager.php プロジェクト: mclkim/webftp
 protected function resizeImage($tempFilePath, $thumbnailParams, $thumbnailPath)
 {
     /**
      * https://github.com/eventviva/php-image-resize
      *
      * PHP must be enabled:
      * extension=php_mbstring.dll
      * extension=php_exif.dll
      *
      * // $image = new ImageResize ( $tempFilePath );
      * // $image->resizeToBestFit ( $thumbnailParams ['width'], $thumbnailParams ['height'] );
      * // $image->save ( $thumbnailPath );
      */
     try {
         $image = new SimpleImage();
         $image->load($tempFilePath)->best_fit($thumbnailParams['width'], $thumbnailParams['height'])->save($thumbnailPath);
     } catch (Exception $e) {
         throw new SystemException($e->getMessage());
     }
 }
コード例 #4
0
 public function load($filename)
 {
     $this->image_class->load($filename);
     return $this;
 }
コード例 #5
0
ファイル: Utils.php プロジェクト: Apretaste/Core
 /**
  * Reduce image size and optimize the image quality
  *
  * @author salvipascual
  * @author kuma
  * @version 2.0
  * @param String $imagePath, path to the image
  * @param number $width Fit to width
  * @param number $height Fit to height
  * @param number $quality Decrease/increase quality
  * @param string $format Convert to format
  * @return boolean
  */
 public function optimizeImage($imagePath, $width = "", $height = "", $quality = 70, $format = 'image/jpeg')
 {
     if (!class_exists('SimpleImage')) {
         include_once "../lib/SimpleImage.php";
     }
     try {
         $img = new SimpleImage();
         $img->load($imagePath);
         if (!empty($width)) {
             $img->fit_to_width($width);
         }
         if (!empty($height)) {
             $img->fit_to_height($height);
         }
         $img->save($imagePath, $quality, $format);
     } catch (Exception $e) {
         return false;
     }
     return true;
 }