private function generate_style($file, $dim, $quality) { $file_name = basename($file); $dir = dirname($file); $new_file = "_cache/" . $dir . "/" . $this->url_safe($dim) . "-" . $file_name; if (!File::exists($file)) { return null; } if (!File::exists($new_file) || File::isNewer($file, $new_file)) { if (!is_dir(dirname($new_file))) { mkdir(dirname($new_file), 0777, true); } $image = new Image($file); $resize = true; list($width, $height, $fix, $crop, $vh) = $this->parse_dim($dim); if ($fix) { $dimension = Image::NONE; } else { $dimension = Image::WIDTH; $wd = $image->width - $width; $hd = $image->height - $height; $pp = $image->width / $image->height * $hd; if ($vh) { if ($vh == 'v') { $dimension = Image::HEIGHT; if (abs($wd) < abs($hd)) { $crop = true; } } elseif ($vh == 'h') { $dimension = Image::WIDTH; if ($wd < 0) { //$resize = false; } else { } } } else { if ($crop) { if ($wd >= $hd && $pp < $wd || $wd < 1 && $pp < $wd) { $dimension = Image::HEIGHT; } } else { if ($wd <= $hd && $pp > $wd || $wd > 1 && $pp > $wd) { $dimension = Image::HEIGHT; } } } } if ($resize) { $image->resize($width, $height, $dimension); } if ($crop) { $image->crop($width, $height, null); } $image->save($new_file, $quality); } $info = getimagesize($new_file); $ret = array(); $ret['width'] = $info[0]; $ret['height'] = $info[1]; $ret['url'] = "/" . $new_file; #backwards compatibility $ret['image_url'] = $ret['url']; return $ret; }
/** * is_file_newer * Checks to see if $file is newer than $compare_to_this_one * * @deprecated Use File::isNewer() instead * * @param string $file File for comparing * @param string $compare_to_this_one Path and name of file to compare against $file * @return boolean */ public static function is_file_newer($file, $compare_to_this_one) { Log::warn("Use of Statamic_Helper::is_file_newer() is deprecated. Use File::isNewer() instead.", "core", "Statamic_Helper"); return File::isNewer($file, $compare_to_this_one); }