/** * Get a new folder * */ static function NewFolder() { global $dataDir; $new_index = gp_resized::NewIndex(); return $dataDir . '/data/_resized/' . $new_index; }
/** * Create a resized image of the file at $src_relative * */ static function CreateImage($src_relative, $width, $height) { global $dataDir; $src_path = $dataDir . '/data/_uploaded' . $src_relative; if (!file_exists($src_path)) { return false; } //compare to actual size includeFile('tool/Images.php'); $src_img = thumbnail::getSrcImg($src_path); if (!$src_img) { return false; } //Original Size $actual_w = imagesx($src_img); $actual_h = imagesy($src_img); if ($actual_w <= $width && $actual_h <= $height) { return false; } $info = gp_resized::ImageInfo($src_relative, $width, $height); if (!$info) { return false; } $dest_index = $info['index']; if (!$dest_index) { $dest_index = gp_resized::NewIndex(); } $dest_path = $dataDir . '/data/_resized/' . $dest_index . '/' . $info['name']; $exists_before = file_exists($dest_path); //make sure the folder exists if (!gpFiles::CheckDir(common::DirName($dest_path))) { return false; } //create new resized image if (!thumbnail::createImg($src_img, $dest_path, 0, 0, 0, 0, $width, $height, $actual_w, $actual_h)) { return false; } //not needed if the resized image is larger than the original if (filesize($dest_path) > filesize($src_path)) { if (!$exists_before) { unlink($dest_path); } return false; } $data['index'] = $dest_index; $data['w'] = $width; $data['h'] = $height; $data['img'] = $src_relative; return $data; }