Example #1
0
 /**
  * @param string $filename
  * @param int $width
  * @param int $height
  * @return null|string
  */
 function resize($filename, $width, $height)
 {
     if (!is_file(DIR_IMAGE . $filename)) {
         return null;
     }
     $info = pathinfo($filename);
     $extension = $info['extension'];
     if ($extension == 'ico') {
         $new_image = $filename;
     } else {
         $old_image = $filename;
         $new_image = 'thumbnails/' . substr($filename, 0, strrpos($filename, '.')) . '-' . $width . 'x' . $height . '.' . $extension;
         if (!is_file(DIR_IMAGE . $new_image) || filemtime(DIR_IMAGE . $old_image) > filemtime(DIR_IMAGE . $new_image)) {
             $path = '';
             $directories = explode('/', dirname(str_replace('../', '', $new_image)));
             foreach ($directories as $directory) {
                 $path = $path . '/' . $directory;
                 if (!file_exists(DIR_IMAGE . $path)) {
                     @mkdir(DIR_IMAGE . $path, 0777);
                     chmod(DIR_IMAGE . $path, 0777);
                 }
             }
             $image = new AImage(DIR_IMAGE . $old_image);
             $image->resizeAndSave(DIR_IMAGE . $new_image, $width, $height, array('quality' => $this->config->get('config_image_quality')));
             unset($image);
         }
     }
     if (isset($this->request->server['HTTPS']) && ($this->request->server['HTTPS'] == 'on' || $this->request->server['HTTPS'] == '1')) {
         return HTTPS_IMAGE . $new_image;
     } else {
         return HTTP_IMAGE . $new_image;
     }
 }
Example #2
0
 /**
  * @param $filename - relative file path
  * @param int $width - in pixels
  * @param int $height - in pixels
  * @param null $alias - alias filename for saving
  * @param string $mode - can be url or file.
  * @return null|string - string is URL or abs file path
  */
 public function resize($filename, $width = 0, $height = 0, $alias = null, $mode = 'url')
 {
     if (!is_file(DIR_IMAGE . $filename) && !is_file(DIR_RESOURCE . 'image/' . $filename)) {
         return null;
     }
     $old_image_filepath = is_file(DIR_IMAGE . $filename) ? DIR_IMAGE . $filename : '';
     $old_image_filepath = $old_image_filepath == '' && is_file(DIR_RESOURCE . 'image/' . $filename) ? DIR_RESOURCE . 'image/' . $filename : $old_image_filepath;
     $https = $this->request->server['HTTPS'];
     if ($https == 'on' || $https == '1') {
         $http_path = HTTPS_IMAGE;
     } else {
         $http_path = HTTP_IMAGE;
     }
     //when need to get abs path of result
     if ($mode == 'path') {
         $http_path = DIR_IMAGE;
     }
     $info = pathinfo($filename);
     $extension = $info['extension'];
     $alias = !$alias ? $filename : dirname($filename) . '/' . basename($alias);
     $new_image = 'thumbnails/' . substr($alias, 0, strrpos($alias, '.')) . '-' . $width . 'x' . $height . '.' . $extension;
     $new_image_filepath = DIR_IMAGE . $new_image;
     //retina variant
     $new_image2x = 'thumbnails/' . substr($alias, 0, strrpos($alias, '.')) . '-' . $width . 'x' . $height . '@2x.' . $extension;
     $new_image_filepath2x = DIR_IMAGE . $new_image2x;
     if (!file_exists($new_image_filepath) || filemtime($old_image_filepath) > filemtime($new_image_filepath) || !file_exists($new_image_filepath2x) || filemtime($old_image_filepath) > filemtime($new_image_filepath2x)) {
         $path = '';
         $directories = explode('/', dirname(str_replace('../', '', $new_image)));
         foreach ($directories as $directory) {
             $path = $path . '/' . $directory;
             if (!file_exists(DIR_IMAGE . $path)) {
                 @mkdir(DIR_IMAGE . $path, 0777);
                 chmod(DIR_IMAGE . $path, 0777);
             }
         }
         $image = new AImage($old_image_filepath);
         $quality = $this->config->get('config_image_quality');
         $image->resizeAndSave($new_image_filepath, $width, $height, array('quality' => $quality));
         unset($image);
         if ($this->config->get('config_retina_enable')) {
             $image = new AImage($old_image_filepath);
             $image->resizeAndSave($new_image_filepath2x, $width * 2, $height * 2, array('quality' => $quality));
             unset($image);
         }
     }
     if ($this->config->get('config_retina_enable') && isset($this->request->cookie['HTTP_IS_RETINA'])) {
         $new_image = $new_image2x;
     }
     return $http_path . $new_image;
 }
Example #3
0
 private function _check_create_thumb($filename, $resource_filename, $width, $height)
 {
     if (!file_exists(DIR_IMAGE . $filename) || filemtime($resource_filename) > filemtime(DIR_IMAGE . $filename)) {
         $path = '';
         $directories = explode('/', dirname(str_replace('../', '', $filename)));
         foreach ($directories as $directory) {
             $path = $path . '/' . $directory;
             if (!file_exists(DIR_IMAGE . $path)) {
                 @mkdir(DIR_IMAGE . $path, 0777);
                 chmod(DIR_IMAGE . $path, 0777);
             }
         }
         $image = new AImage($resource_filename);
         $image->resizeAndSave(DIR_IMAGE . $filename, $width, $height, array('quality' => $this->config->get('config_image_quality')));
         unset($image);
     }
 }