Add use PATH_ROOT. Refactoring. Some fixes for checking file_exists, is_read, is_file in UploadHelper.
This commit is contained in:
@ -2,22 +2,31 @@
|
|||||||
|
|
||||||
abstract class Upload
|
abstract class Upload
|
||||||
{
|
{
|
||||||
/**
|
const PATH_ROOT = '/var/www/10ballov/face/htdocs';
|
||||||
* @param $file array (ex. ['tmp_name' => '...', 'name' => '...', 'type' => '...'])
|
public static function getGreagwarImage($file_path)
|
||||||
* @return Image
|
|
||||||
*/
|
|
||||||
public static function image($file)
|
|
||||||
{
|
{
|
||||||
require_once PATH . '/lib/GreagwarImage/GreagwarImage.php';
|
require_once PATH . '/lib/GreagwarImage/GreagwarImage.php';
|
||||||
$greagwar_image = new GreagwarImage($file['tmp_name']);
|
$greagwar_image = new GreagwarImage($file_path);
|
||||||
$greagwar_image->setCacheDir('media/cache/images');
|
$greagwar_image->setCacheDir(self::PATH_ROOT . '/media/cache/images');
|
||||||
|
return $greagwar_image;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @param $file array (ex. ['tmp_name' => '...', 'name' => '...', 'type' => '...'])
|
||||||
|
* @param $force_create_variants bool
|
||||||
|
* @return Image
|
||||||
|
*/
|
||||||
|
public static function image($file, $force_create_variants = true)
|
||||||
|
{
|
||||||
$image = new Image;
|
$image = new Image;
|
||||||
$image->original_filename = $file['name'];
|
$image->original_filename = $file['name'];
|
||||||
$image->type = $file['type'];
|
$image->type = $file['type'];
|
||||||
|
$greagwar_image = self::getGreagwarImage($file['tmp_name']);
|
||||||
self::saveImage($image, $greagwar_image);
|
self::saveImage($image, $greagwar_image);
|
||||||
foreach (Image::$sizes as $size) {
|
if ($force_create_variants) {
|
||||||
$size_parts = explode('x', $size);
|
foreach (Image::$sizes as $size) {
|
||||||
self::saveImage($image->getVariant($size), $greagwar_image, $size_parts[0] ? : null, $size_parts[1] ? : null);
|
$size_parts = explode('x', $size);
|
||||||
|
self::saveImage($image->getVariant($size), $greagwar_image, $size_parts[0] ? : null, $size_parts[1] ? : null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return $image;
|
return $image;
|
||||||
}
|
}
|
||||||
@ -29,29 +38,18 @@ abstract class Upload
|
|||||||
* @param null $height
|
* @param null $height
|
||||||
* @param bool $crop
|
* @param bool $crop
|
||||||
*/
|
*/
|
||||||
protected static function saveImage($image, $greagwar_image, $width = null, $height = null, $crop = true)
|
public static function saveImage($image, $greagwar_image, $width = null, $height = null, $crop = true)
|
||||||
{
|
{
|
||||||
if ($width || $height) {
|
if ($width || $height) {
|
||||||
$greagwar_image->resize($width, $height, 0xffffff, false, false, $crop);
|
$greagwar_image->resize($width, $height, 0xffffff, false, false, $crop);
|
||||||
}
|
}
|
||||||
$file_path = $greagwar_image->cacheFile($greagwar_image->guessType(), 87, true);
|
$file_path = $greagwar_image->cacheFile($greagwar_image->guessType(), 87, true);
|
||||||
|
$image->size = filesize($file_path);
|
||||||
$path_parts = pathinfo($file_path);
|
$path_parts = pathinfo($file_path);
|
||||||
$image->path = $path_parts['dirname'];
|
$image->path = preg_replace('#^' . self::PATH_ROOT . '/#', '', $path_parts['dirname']);
|
||||||
$image->filename = $path_parts['basename'];
|
$image->filename = $path_parts['basename'];
|
||||||
$image->size = filesize($image->path . '/' . $image->filename);
|
|
||||||
$image->width = $greagwar_image->width();
|
$image->width = $greagwar_image->width();
|
||||||
$image->height = $greagwar_image->height();
|
$image->height = $greagwar_image->height();
|
||||||
$image->setIsNotEmpty();
|
$image->setIsNotEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function imageCompareAspectRatio($proportion, $file_path)
|
|
||||||
{
|
|
||||||
$imagesize = getimagesize($file_path);
|
|
||||||
$proprtion_parts = explode('x', $proportion);
|
|
||||||
if ($proprtion_parts[0] / $proprtion_parts[1] === $imagesize[0] / $imagesize[1]) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -4,22 +4,26 @@ abstract class UploadHelper
|
|||||||
{
|
{
|
||||||
public static function imageCompareAspectRatio($proportion, $file_path)
|
public static function imageCompareAspectRatio($proportion, $file_path)
|
||||||
{
|
{
|
||||||
$imagesize = getimagesize($file_path);
|
if (file_exists($file_path) && is_readable($file_path) && is_file($file_path)) {
|
||||||
$proprtion_parts = explode('x', $proportion);
|
if ($imagesize = getimagesize($file_path)) {
|
||||||
if ($proprtion_parts[0] / $proprtion_parts[1] === $imagesize[0] / $imagesize[1]) {
|
$proprtion_parts = explode('x', $proportion);
|
||||||
return true;
|
if ($proprtion_parts[0] / $proprtion_parts[1] === $imagesize[0] / $imagesize[1]) {
|
||||||
} else {
|
return true;
|
||||||
false;
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
public static function imageCheckMinSize($size, $file_path)
|
public static function imageCompareSize($size, $file_path)
|
||||||
{
|
{
|
||||||
$imagesize = getimagesize($file_path);
|
if (file_exists($file_path) && is_readable($file_path) && is_file($file_path)) {
|
||||||
$size_parts = explode('x', $size);
|
if ($imagesize = getimagesize($file_path)) {
|
||||||
if ($imagesize[0] >= $size_parts[0] && $imagesize[1] >= $size_parts[1]) {
|
$size_parts = explode('x', $size);
|
||||||
return true;
|
if ($imagesize[0] == $size_parts[0] && $imagesize[1] == $size_parts[1]) {
|
||||||
} else {
|
return true;
|
||||||
return false;
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user