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; }
/** * Upload image. * * @param string $dest target directory to upload * @param string $field request fieldname * @param stdClass $image property where sets ouptput with this format: * $image->tmp ... request template file name * $image->name ... uploaded image name * $image->apath ... absolute path to image * $image->rpath ... real path to image * @param string $error property to set error messages * @return boolean */ function upload($dest, $field, &$image, &$error) { $adir = $dest; $rdir = JURI::root() . str_replace(DS, '/', $dest); $rdir = str_replace('//', '/', $dest); if (!file_exists($adir)) { if (!@mkdir($adir, 0775, true)) { $mainframe = JFactory::getApplication(); /* @var $mainframe JApplication */ $mainframe->enqueueMessage(sprintf(JText::_('Unable create directory %s'), $adir), 'error'); return false; } } if (isset($_FILES[$field])) { $request =& $_FILES[$field]; $image = new stdClass(); $image->tmp = $request['tmp_name']; $image->name = $request['name']; if ($request['error'] == 0) { $zip = new JArchiveZip(); $data = JFile::read($image->tmp); $isZip = $zip->checkZipData($data); unset($data); if ($isZip) { $tmpDir = AImage::getTmpDir(); $zip->extract($image->tmp, $tmpDir); unset($zip); $files =& JFolder::files($tmpDir, '.', true, true); $count = count($files); for ($i = 0; $i < $count; $i++) { $image->tmp = $files[$i]; $image->name = JFile::getName($image->tmp); AImage::save($image, $adir, $rdir); } JFolder::delete($tmpDir); return true; } else { unset($zip); return AImage::save($image, $adir, $rdir); } } } return false; }
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'); } }