public function resize($filename, $width = 0, $height = 0) { if (!is_file(DIR_IMAGE . $filename)) { return null; } $https = $this->request->server['HTTPS']; if ($https == 'on' || $https == '1') { $http_path = HTTPS_IMAGE; } else { $http_path = HTTP_IMAGE; } $info = pathinfo($filename); $extension = $info['extension']; $old_image = $filename; $new_image = 'thumbnails/' . substr($filename, 0, strrpos($filename, '.')) . '-' . $width . 'x' . $height . '.' . $extension; if (!file_exists(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->resize($width, $height); $image->save(DIR_IMAGE . $new_image); unset($image); } return $http_path . $new_image; }
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->resize($width, $height); $image->save(DIR_IMAGE . $filename); unset($image); } }
public function getResourceThumb($resource_id, $width = '', $height = '', $language_id = '') { if (!$language_id) { $language_id = $this->config->get('storefront_language_id'); } $resource = $this->getResource($resource_id, $language_id); switch ($this->type) { case 'image': if (!$resource['default_icon']) { $resource['default_icon'] = 'no_image.jpg'; } break; default: if (!$resource['default_icon']) { $resource['default_icon'] = 'no_image.jpg'; } $this->load->model('tool/image'); $this->model_tool_image->resize($resource['default_icon'], $width, $height); return $this->model_tool_image->resize($resource['default_icon'], $width, $height); } if (!empty($resource['resource_code'])) { return $resource['resource_code']; } $old_image = DIR_RESOURCE . $this->type_dir . $resource['resource_path']; $info = pathinfo($old_image); $extension = $info['extension']; if ($extension != 'ico') { if (!is_file($old_image)) { $this->load->model('tool/image'); $this->model_tool_image->resize($resource['default_icon'], $width, $height); return $this->model_tool_image->resize($resource['default_icon'], $width, $height); } $name = preg_replace('/[^a-zA-Z0-9]/', '', $resource['name']); //Build thumbnails path similar to resource library path $new_image = 'thumbnails/' . dirname($resource['resource_path']) . '/' . $name . '-' . $resource['resource_id'] . '-' . $width . 'x' . $height . '.' . $extension; if (!file_exists(DIR_IMAGE . $new_image) || filemtime($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($old_image); $image->resize($width, $height); $image->save(DIR_IMAGE . $new_image); unset($image); } if (HTTPS === true) { return HTTPS_IMAGE . $new_image; } else { return HTTP_IMAGE . $new_image; } } else { // returns ico-file as is return $this->buildResourceURL($resource['resource_path'], 'full'); } }