public function resize($filename, $width, $height, $crop = false, $watermark = false, $gray = false) { if (!$width && !$height) { $width = 1; $height = 1; } if (!file_exists($this->dirImages . $filename) || !is_file($this->dirImages . $filename)) { $filename = JO_Registry::forceGet('no_image'); if (!file_exists($this->dirImages . $filename) || !is_file($this->dirImages . $filename)) { $filename = '/no_image.jpg'; if (!file_exists($this->dirImages . $filename) || !is_file($this->dirImages . $filename)) { return; } } } $info = pathinfo($filename); $extension = $info['extension']; $gray_name = ''; if ($gray) { $gray_name = '_gray'; } if ($crop) { $gray_name .= '_crop'; } if ($watermark && JO_Registry::get($watermark) && file_exists(BASE_PATH . '/uploads' . JO_Registry::get($watermark))) { $gray_name .= '_watermark'; } $old_image = $filename; $tmp = substr($filename, 0, strrpos($filename, '.')); $filename = substr($tmp, 0, strrpos($tmp, '/')) . '/' . md5(basename($tmp)) . '-' . md5($filename); $new_image = 'cache' . $filename . '-' . $width . 'x' . $height . $gray_name . '.' . $extension; $new_image = str_replace('/../', '/', $new_image); if (!file_exists($this->dirImages . $new_image) || filemtime($this->dirImages . $old_image) > filemtime($this->dirImages . $new_image)) { $path = ''; $directories = explode('/', dirname(str_replace('../', '', $new_image))); foreach ($directories as $directory) { $path = $path . '/' . $directory; if (!file_exists($this->dirImages . $path)) { @mkdir($this->dirImages . $path, 0777, true); } } $image = new JO_GDThumb($this->dirImages . $old_image); if ($crop === false) { $image->resize($width, $height); } else { $image->resize_crop($width, $height); } if ($watermark && JO_Registry::get($watermark) && file_exists(BASE_PATH . '/uploads/' . JO_Registry::get($watermark))) { $image->watermark(BASE_PATH . '/uploads/' . JO_Registry::get($watermark), false); } $image->save($this->dirImages . $new_image, $gray); } return $this->httpImages . $new_image; }