Beispiel #1
0
        continue;
    }
    $dest = $out_path . '/' . $file->getFilename();
    if (file_exists($dest)) {
        unlink($dest);
    }
    ?>

        <h2><?php 
    echo $file->getFilename();
    ?>
</h2>
        <?php 
    //Compress image
    copy($file->getPathname(), $dest);
    $optimizer = new Tinyfier_Image_Optimizer();
    $optimizer->verbose = true;
    $optimizer->mode = Tinyfier_Image_Optimizer::MODE_LOSSY;
    $optimizer->level = $_GET['level'];
    $optimizer->optimize($dest);
    ?>
        <div class="row-fluid">
            <div class="span6">
                <h4>Original
                    <small><?php 
    echo format_size(filesize($file->getPathname()));
    ?>
</small>
                </h4>
                <img src="<?php 
    echo str_replace(dirname(__FILE__) . '/', '', $file->getPathname());
Beispiel #2
0
 /**
  * Save the current image on the specified path
  *
  * @param string        $path           Path to the saved file, NULL to send it to the browser
  * @param int|boolean   $quality        Lossy quality of the saved file. TRUE for maximum quality and LOSSLESS optimization
  * @param boolean|array $optimize       Optimize image after save. It can be an array of Tinyfier_Image_Optimizer::process settings
  * @param boolean       $check_is_equal Check, before save, that the file exists and it's equal to the current image (so it doesnt have to optimize again)
  * @param mixed         $format         Output format for the image, NULL to detect it from the file name
  *
  * @return boolean
  * @warning Optimization is not available when the image is sent to the browser
  */
 public function save($path, $quality = 85, $optimize = true, $check_is_equal = false, $format = null)
 {
     //Check if image exists and is equal
     if ($check_is_equal && file_exists($path) && self::equal($this, $path)) {
         return false;
         //Same images, don't overwrite
     }
     if (!isset($format)) {
         $format = str_replace('.', '', strtolower(pathinfo($path, PATHINFO_EXTENSION)));
     }
     //Save image
     switch ($format) {
         case 'jpg':
         case 'jpeg':
         case IMAGETYPE_JPEG:
             $this->set_bg_color();
             $success = imagejpeg($this->_handle, $path, $optimize || $quality === true ? 100 : $quality);
             break;
         case 'gif':
         case IMAGETYPE_GIF:
             $success = imagegif($this->_handle, $path);
             break;
         case 'png':
         case IMAGETYPE_PNG:
             imagesavealpha($this->_handle, true);
             $success = imagepng($this->_handle, $path, 9, PNG_ALL_FILTERS);
             $format = 'png';
             break;
         default:
             throw new InvalidArgumentException("Unrecognized format '{$format}'");
     }
     //Optimize
     if ($optimize && $path != null && $success) {
         $optimizer = new Tinyfier_Image_Optimizer();
         $optimizer->mode = $quality === true ? Tinyfier_Image_Optimizer::MODE_LOSSLESS : Tinyfier_Image_Optimizer::MODE_LOSSY;
         $optimizer->lossy_quality = $quality;
         if (is_array($optimize)) {
             foreach ($optimize as $k => $v) {
                 $optimizer->{$k} = $v;
             }
         }
         $optimizer->optimize($path);
     }
     return $success;
 }