new pisilinux web sites
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
<?php namespace ZN\Image;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
trait CallableFilterMethod
|
||||
{
|
||||
/**
|
||||
* Keeps filters
|
||||
*/
|
||||
protected $filters =
|
||||
[
|
||||
'negate' , 'grayscale' , 'brightness' ,
|
||||
'constrast' , 'colorize' , 'edgedetect' ,
|
||||
'emboss' , 'gaussianBlur', 'selectiveBlur',
|
||||
'meanRemoval', 'smooth' , 'pixelate'
|
||||
];
|
||||
|
||||
/**
|
||||
* Magic call
|
||||
*
|
||||
* @param string $method
|
||||
* @param string $parameters
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
protected function callable($method, $parameters)
|
||||
{
|
||||
if( in_array($method, $this->filters) )
|
||||
{
|
||||
$this->filter($method, ...$parameters);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php namespace ZN\Image;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
trait CallableFilters
|
||||
{
|
||||
/**
|
||||
* Keeps GD filters.
|
||||
*/
|
||||
protected $filters;
|
||||
|
||||
/**
|
||||
* Callable GD method
|
||||
*
|
||||
* @param string $method
|
||||
* @param array $parameters
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function __call($method, $parameters)
|
||||
{
|
||||
$this->filters[] = [$method, $parameters];
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php namespace ZN\Image;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
class ColorConverter
|
||||
{
|
||||
public static function run($rgb)
|
||||
{
|
||||
// Renkler küçük isimlerle yazılmıştır.
|
||||
$rgb = strtolower($rgb);
|
||||
$colors = Properties::$colors;
|
||||
|
||||
if( isset($colors[$rgb]) )
|
||||
{
|
||||
return $colors[$rgb];
|
||||
}
|
||||
else
|
||||
{
|
||||
return $rgb ?? '0|0|0|127';
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php namespace ZN\Image;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
class CoordinateRateCalculator
|
||||
{
|
||||
/**
|
||||
* Calculates the ratio according to the entered numerical value.
|
||||
*
|
||||
* @param float $size
|
||||
* @param float &$c1
|
||||
* @param float &$c2
|
||||
*/
|
||||
public static function run($size, &$c1, &$c2)
|
||||
{
|
||||
if( $size > 0 )
|
||||
{
|
||||
if( $size <= $c2 )
|
||||
{
|
||||
$rate = $c2 / $size; $c2 = $size; $c1 = $c1 / $rate;
|
||||
}
|
||||
else
|
||||
{
|
||||
$rate = $size / $c2; $c2 = $size; $c1 = $c1 * $rate;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php namespace ZN\Image\Exception;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
use ZN\Exception;
|
||||
|
||||
class FontNotFoundException extends Exception
|
||||
{
|
||||
const lang =
|
||||
[
|
||||
'en' => '`%` font could not be found!',
|
||||
'tr' => '`%` fontu bulunamadı!'
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php namespace ZN\Image\Exception;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
use ZN\Exception;
|
||||
|
||||
class ImageNotFoundException extends Exception
|
||||
{
|
||||
const lang =
|
||||
[
|
||||
'en' => '`%` file could not be found!',
|
||||
'tr' => '`%` dosyası bulunamadı!'
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php namespace ZN\Image\Exception;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
use ZN\Exception;
|
||||
|
||||
class InvalidArgumentException extends Exception
|
||||
{
|
||||
const lang =
|
||||
[
|
||||
'tr' => 'Geçersiz parametre türü! % türü olmalıdır.',
|
||||
'en' => 'Invalid parameter type! Must be% type.'
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php namespace ZN\Image\Exception;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
use ZN\Exception;
|
||||
|
||||
class InvalidImageFileException extends Exception
|
||||
{
|
||||
const lang =
|
||||
[
|
||||
'en' => '`%` file is not an image file!',
|
||||
'tr' => '`%` dosyası resim dosyası değildir!'
|
||||
];
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,49 @@
|
||||
<?php namespace ZN\Image;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
use ZN\Singleton;
|
||||
|
||||
class GDFilter
|
||||
{
|
||||
/**
|
||||
* Applies the used filters belonging to the GD class.
|
||||
*
|
||||
* @param string $file
|
||||
* @param array $filters
|
||||
*/
|
||||
public static function apply($file, $filters)
|
||||
{
|
||||
if( ! empty($filters) )
|
||||
{
|
||||
$gd = self::getSingletonGDClass();
|
||||
|
||||
$gd->canvas($file);
|
||||
|
||||
foreach( $filters as $filter )
|
||||
{
|
||||
$method = $filter[0];
|
||||
$parameters = $filter[1] ?? [];
|
||||
|
||||
$gd->$method(...(array) $parameters);
|
||||
}
|
||||
|
||||
$gd->generate(MimeTypeFinder::get($file), $file);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected get singleton GD class
|
||||
*/
|
||||
protected static function getSingletonGDClass()
|
||||
{
|
||||
return Singleton::class('ZN\Image\GD');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,373 @@
|
||||
<?php namespace ZN\Image;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
interface GDInterface
|
||||
{
|
||||
/**
|
||||
* Get info
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function info() : array;
|
||||
|
||||
/**
|
||||
* Load ttf font
|
||||
*
|
||||
* @return GD
|
||||
*/
|
||||
public function load($ttfpath) : GD;
|
||||
|
||||
/**
|
||||
* Sets canvas
|
||||
*
|
||||
* @param mixed $width
|
||||
* @param mixed $height = NULL
|
||||
* @param mixed $rgb = 'transparent'
|
||||
* @param mixed $real = false
|
||||
*
|
||||
* @return GD
|
||||
*/
|
||||
public function canvas($width, $height, $rgb, $real) : GD;
|
||||
|
||||
/**
|
||||
* Creates form
|
||||
*
|
||||
* @param string $source
|
||||
*
|
||||
* @return resource
|
||||
*/
|
||||
public function createFrom(string $source);
|
||||
|
||||
/**
|
||||
* Set size
|
||||
*
|
||||
* @param string $fileName
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
public function size(string $fileName) : \stdClass;
|
||||
|
||||
/**
|
||||
* Get file extension
|
||||
*
|
||||
* @param string $type = 'jpeg'
|
||||
* @param bool $dot = true
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function extension(string $type = 'jpeg', bool $dot = true) : string;
|
||||
|
||||
/**
|
||||
* Get mime type
|
||||
*
|
||||
* @param string $type = 'jpeg'
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function mime(string $type = 'jpeg') : string;
|
||||
|
||||
/**
|
||||
* Sets alpha blending
|
||||
*
|
||||
* @param bool $blendMode = NULL
|
||||
*
|
||||
* @return GD
|
||||
*/
|
||||
public function alphaBlending(?bool $blendMode = NULL) : GD;
|
||||
|
||||
/**
|
||||
* Sets save alpha
|
||||
*
|
||||
* @param bool $save = true
|
||||
*
|
||||
* @return GD
|
||||
*/
|
||||
public function saveAlpha(bool $save = true) : GD;
|
||||
|
||||
/**
|
||||
* Sets smooth
|
||||
*
|
||||
* @param bool $mode = true
|
||||
*
|
||||
* @return GD
|
||||
*/
|
||||
public function smooth(bool $mode = true) : GD;
|
||||
|
||||
/**
|
||||
* Creates Arc
|
||||
*
|
||||
* @param array $settings []
|
||||
*
|
||||
* @return GD
|
||||
*/
|
||||
public function arc(array $settings = []) : GD;
|
||||
|
||||
/**
|
||||
* Creates Ellipse
|
||||
*
|
||||
* @param array $settings []
|
||||
*
|
||||
* @return GD
|
||||
*/
|
||||
public function ellipse(array $settings = []) : GD;
|
||||
|
||||
/**
|
||||
* Creates Polygon
|
||||
*
|
||||
* @param array $settings []
|
||||
*
|
||||
* @return GD
|
||||
*/
|
||||
public function polygon(array $settings = []) : GD;
|
||||
|
||||
/**
|
||||
* Creates Rectangle
|
||||
*
|
||||
* @param array $settings []
|
||||
*
|
||||
* @return GD
|
||||
*/
|
||||
public function rectangle(array $settings = []) : GD;
|
||||
|
||||
/**
|
||||
* Fill
|
||||
*
|
||||
* @param array $settings []
|
||||
*
|
||||
* @return GD
|
||||
*/
|
||||
public function fill(array $settings = []) : GD;
|
||||
|
||||
/**
|
||||
* Filter
|
||||
*
|
||||
* @param string $filter
|
||||
* @param int $arg1 = NULL
|
||||
* @param int $arg2 = NULL
|
||||
* @param int $arg3 = NULL
|
||||
* @param int $arg4 = NULL
|
||||
*
|
||||
* @return GD
|
||||
*/
|
||||
public function filter(string $filter, ?int $arg1 = NULL, ?int $arg2 = NULL, ?int $arg3 = NULL, ?int $arg4 = NULL) : GD;
|
||||
|
||||
/**
|
||||
* Flip
|
||||
*
|
||||
* @param string $type = 'both'
|
||||
*
|
||||
* @return GD
|
||||
*/
|
||||
public function flip(string $type) : GD;
|
||||
|
||||
/**
|
||||
* Creates char
|
||||
*
|
||||
* @param string $text
|
||||
* @param array $settings = []
|
||||
*
|
||||
* @return GD
|
||||
*/
|
||||
public function char(string $char, array $settings = []) : GD;
|
||||
|
||||
/**
|
||||
* Creates text
|
||||
*
|
||||
* @param string $text
|
||||
* @param array $settings = []
|
||||
*
|
||||
* @return GD
|
||||
*/
|
||||
public function text(string $text, array $settings = []) : GD;
|
||||
|
||||
/**
|
||||
* Creates ttftext
|
||||
*
|
||||
* @param string $text
|
||||
* @param array $settings = []
|
||||
*
|
||||
* @return GD
|
||||
*/
|
||||
public function ttftext(string $text, array $settings = []) : GD;
|
||||
|
||||
/**
|
||||
* Set convolution
|
||||
*
|
||||
* @param array $matrix
|
||||
* @param float $div = 0
|
||||
* @param float $offset = 0
|
||||
*
|
||||
* @return GD
|
||||
*/
|
||||
public function convolution(array $matrix, Float $div = 0, Float $offset = 0) : GD;
|
||||
|
||||
/**
|
||||
* Set interlace
|
||||
*
|
||||
* @param int $interlace = 0
|
||||
*
|
||||
* @return GD
|
||||
*/
|
||||
public function interlace(int $interlace = 0) : GD;
|
||||
|
||||
/**
|
||||
* Copy
|
||||
*
|
||||
* @param string|resource $source
|
||||
* @param array $settings = []
|
||||
*
|
||||
* @return GD
|
||||
*/
|
||||
public function copy($source, array $settings = []) : GD;
|
||||
|
||||
/**
|
||||
* Mix
|
||||
*
|
||||
* @param string|resource $source
|
||||
* @param array $settings = []
|
||||
*
|
||||
* @return GD
|
||||
*/
|
||||
public function mix($source, array $settings = []) : GD;
|
||||
|
||||
/**
|
||||
* Mixgray
|
||||
*
|
||||
* @param string|resource $source
|
||||
* @param array $settings = []
|
||||
*
|
||||
* @return GD
|
||||
*/
|
||||
public function mixGray($source, array $settings = []) : GD;
|
||||
|
||||
/**
|
||||
* Resize / Resample
|
||||
*
|
||||
* @param string|resource $source
|
||||
* @param array $settings = []
|
||||
*
|
||||
* @return GD
|
||||
*/
|
||||
public function resample($source, array $settings = []) : GD;
|
||||
|
||||
/**
|
||||
* Resize
|
||||
*
|
||||
* @param string|resource $source
|
||||
* @param array $settings = []
|
||||
*
|
||||
* @return GD
|
||||
*/
|
||||
public function resize($source, array $settings = []) : GD;
|
||||
|
||||
/**
|
||||
* Crop
|
||||
*
|
||||
* @param array $settings = []
|
||||
*
|
||||
* @return GD
|
||||
*/
|
||||
public function crop(array $settings = []) : GD;
|
||||
|
||||
/**
|
||||
* Auto crop
|
||||
*
|
||||
* @param string $mode = 'default'
|
||||
* @param int $threshold = .5
|
||||
* @param int $color = -1
|
||||
*
|
||||
* @return GD
|
||||
*/
|
||||
public function autoCrop(string $mode = 'default', $threshold = .5, $color = -1) : GD;
|
||||
|
||||
/**
|
||||
* Creates a line
|
||||
*
|
||||
* @param array $settings = []
|
||||
*
|
||||
* @return GD
|
||||
*/
|
||||
public function line(array $settings = []) : GD;
|
||||
|
||||
/**
|
||||
* Get screenshot
|
||||
*
|
||||
* @return GD
|
||||
*/
|
||||
public function screenshot() : GD;
|
||||
|
||||
/**
|
||||
* Set rotate
|
||||
*
|
||||
* @param float $angle
|
||||
* @param string $spaceColor = '0|0|0'
|
||||
*
|
||||
* @return GD
|
||||
*/
|
||||
public function rotate(Float $angle, string $spaceColor = '0|0|0') : GD;
|
||||
|
||||
/**
|
||||
* Set scale
|
||||
*
|
||||
* @param int $width
|
||||
* @param int $height = -1
|
||||
* @param string $method = 'bilinearFixed'
|
||||
*
|
||||
* @return GD
|
||||
*/
|
||||
public function scale(int $width, int $height = -1, string $mode = 'bilinear_fixed') : GD;
|
||||
|
||||
/**
|
||||
* Set interpolation
|
||||
*
|
||||
* @param string $method = 'bilinearFixed'
|
||||
*
|
||||
* @return GD
|
||||
*/
|
||||
public function interpolation(string $method = 'bilinear_fixed') : GD;
|
||||
|
||||
/**
|
||||
* Set pixed
|
||||
*
|
||||
* @param array $settings = []
|
||||
*
|
||||
* @return GD
|
||||
*/
|
||||
public function pixel(array $settings = []) : GD;
|
||||
|
||||
/**
|
||||
* Set thickness
|
||||
*
|
||||
* @param int $thickness = 1
|
||||
*
|
||||
* @return GD
|
||||
*/
|
||||
public function thickness(int $thickness = 1) : GD;
|
||||
|
||||
/**
|
||||
* Set layer effect
|
||||
*
|
||||
* @param string $effect = 'normal'
|
||||
*
|
||||
* @return GD
|
||||
*/
|
||||
public function layerEffect(string $effect = 'normal') : GD;
|
||||
|
||||
/**
|
||||
* Generate Image
|
||||
*
|
||||
* @param string $type = NULL
|
||||
* @param string $save = NULL
|
||||
*
|
||||
* @return resource
|
||||
*/
|
||||
public function generate(string $type, string $save);
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php namespace ZN\Image;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
use ZN\Filesystem;
|
||||
|
||||
class ImageTypeCreator
|
||||
{
|
||||
/**
|
||||
* Image type creator
|
||||
*
|
||||
* @param resources $files
|
||||
* @param string $path
|
||||
* @param int $quality = 0
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function create($files, $path, $quality = 0)
|
||||
{
|
||||
switch( self::getFileExtension($path) )
|
||||
{
|
||||
case 'png' :
|
||||
if( $quality > 10 )
|
||||
{
|
||||
$quality = (int) ($quality / 10);
|
||||
}
|
||||
return imagepng($files, $path, $quality ?: 8 );
|
||||
case 'gif' : return imagegif($files, $path);
|
||||
case 'webp': return imagewebp($files, $path, $quality ?: 80);
|
||||
case 'jpg' :
|
||||
case 'jpeg':
|
||||
default : return imagejpeg($files, $path, $quality ?: 80);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Image create from
|
||||
*/
|
||||
public static function from($path)
|
||||
{
|
||||
switch( self::getFileExtension($path) )
|
||||
{
|
||||
case 'png' : return imagecreatefrompng($path);
|
||||
case 'gif' : return imagecreatefromgif($path);
|
||||
case 'webp': return imagecreatefromwebp($path);
|
||||
case 'jpg' :
|
||||
case 'jpeg':
|
||||
default : return imagecreatefromjpeg($path);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected get file extension
|
||||
*/
|
||||
protected static function getFileExtension($path)
|
||||
{
|
||||
return Filesystem::getExtension($path);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php namespace ZN\Image;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
use ZN\Singleton;
|
||||
|
||||
class MimeTypeFinder
|
||||
{
|
||||
/**
|
||||
* Finder mime type.
|
||||
*
|
||||
* @param string $file
|
||||
*/
|
||||
public static function get($file)
|
||||
{
|
||||
$type = str_replace('image/', '', Singleton::class('ZN\Helpers\Mime')->type($file));
|
||||
|
||||
return $type === 'jpg' ? 'jpeg' : $type;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,179 @@
|
||||
<?php namespace ZN\Image;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
class Properties
|
||||
{
|
||||
public static $colors =
|
||||
[
|
||||
// Transparent
|
||||
'transparent' => '0|0|0|127',
|
||||
|
||||
// Red Types
|
||||
'lightsalmon' => '255|160|122',
|
||||
'salmon' => '250|128|114',
|
||||
'darksalmon' => '233|150|122',
|
||||
'lightcoral' => '240|128|128',
|
||||
'indianred' => '205|92|92',
|
||||
'crimson' => '220|20|60',
|
||||
'firebrick' => '178|34|34',
|
||||
'red' => '255|0|0',
|
||||
'darkred' => '139|0|0',
|
||||
'maroon' => '128|0|0',
|
||||
'tomato' => '255|99|71',
|
||||
'orangered' => '255|69|0',
|
||||
'palevioletred' => '219|112|147',
|
||||
|
||||
// Blue Types
|
||||
'aliceblue' => '240|248|255',
|
||||
'lavender' => '230|230|250',
|
||||
'powderblue' => '176|224|230',
|
||||
'lightblue' => '173|216|230',
|
||||
'lightskyblue' => '135|206|250',
|
||||
'skyblue' => '135|206|235',
|
||||
'deepskyblue' => '0|191|255',
|
||||
'lightsteelblue' => '176|196|222',
|
||||
'dodgerblue' => '30|144|255',
|
||||
'cornflowerblue' => '100|149|237',
|
||||
'steelblue' => '70|130|180',
|
||||
'cadetblue' => '95|158|160',
|
||||
'mediumslateblue' => '123|104|238',
|
||||
'slateblue' => '106|90|205',
|
||||
'darkslateblue' => '72|61|139',
|
||||
'royalblue' => '65|105|225',
|
||||
'blue' => '0|0|255',
|
||||
'mediumblue' => '0|0|205',
|
||||
'darkblue' => '0|0|139',
|
||||
'navy' => '0|0|128',
|
||||
'midnightblue' => '25|25|112',
|
||||
'blueviolet' => '138|43|226',
|
||||
'indigo' => '75|0|130',
|
||||
|
||||
// Light Cyan Types
|
||||
'lightcyan' => '224|255|255',
|
||||
'cyan' => '0|255|255',
|
||||
'aqua' => '0|255|255',
|
||||
'aquamarine' => '127|255|212',
|
||||
'mediumaquamarine' => '102|205|170',
|
||||
'paleturquoise' => '175|238|238',
|
||||
'turquoise' => '64|224|208',
|
||||
'mediumturquoise' => '72|209|204',
|
||||
'darkturquoise' => '0|206|209',
|
||||
'darkcyan' => '0|139|139',
|
||||
'teal' => '0|128|128',
|
||||
|
||||
// Green Types
|
||||
'lawngreen' => '124|252|0',
|
||||
'chartreuse' => '127|255|0',
|
||||
'limegreen' => '50|205|50',
|
||||
'lime' => '0|255|0',
|
||||
'forestgreen' => '34|139|34',
|
||||
'green' => '0|128|0',
|
||||
'darkgreen' => '0|100|0',
|
||||
'greenyellow' => '173|255|47',
|
||||
'springgreen' => '0|255|127',
|
||||
'mediumspringgreen' => '0|250|154',
|
||||
'lightgreen' => '144|238|144',
|
||||
'palegreen' => '152|251|152',
|
||||
'darkseagreen' => '143|188|143',
|
||||
'mediumseagreen' => '60|179|113',
|
||||
'lightseagreen' => '32|178|170',
|
||||
'seagreen' => '46|139|87',
|
||||
'olive' => '128|128|0',
|
||||
'darkolivegreen' => '85|107|47',
|
||||
'olivedrab' => '107|142|35',
|
||||
|
||||
// Grey Types
|
||||
'gainsboro' => '220|220|220',
|
||||
'lightgray' => '211|211|211',
|
||||
'lightgrey' => '211|211|211',
|
||||
'silver' => '192|192|192',
|
||||
'darkgray' => '169|169|169',
|
||||
'darkgrey' => '169|169|169',
|
||||
'gray' => '128|128|128',
|
||||
'grey' => '128|128|128',
|
||||
'dimgray' => '105|105|105',
|
||||
'dimgrey' => '105|105|105',
|
||||
'lightslategray' => '119|136|153',
|
||||
'lightslategrey' => '119|136|153',
|
||||
'slategray' => '112|128|144',
|
||||
'slategrey' => '112|128|144',
|
||||
'darkslategray' => '47|79|79',
|
||||
'darkslategrey' => '47|79|79',
|
||||
'black' => '0|0|0',
|
||||
|
||||
// Yellow Types
|
||||
'lightyellow' => '255|255|224',
|
||||
'lightyellow1' => '255|255|204',
|
||||
'lightyellow2' => '255|255|153',
|
||||
'lightyellow3' => '255|255|102',
|
||||
'lightyellow4' => '255|255|51',
|
||||
'yellow' => '255|255|0',
|
||||
'darkyellow' => '204|204|0',
|
||||
'darkyellow1' => '153|153|0',
|
||||
'darkyellow2' => '128|128|0',
|
||||
'darkyellow3' => '102|102|0',
|
||||
'darkyellow4' => '51|51|0',
|
||||
'lemonchiffon' => '255|250|205',
|
||||
'lightgoldenrodyellow' => '250|250|210',
|
||||
'papayawhip' => '255|239|213',
|
||||
'moccasin' => '255|228|181',
|
||||
'peachpuff' => '255|218|185',
|
||||
'palegoldenrod' => '238|232|170',
|
||||
'khaki' => '240|230|140',
|
||||
'darkkhaki' => '189|183|107',
|
||||
'yellowgreen' => '154|205|50',
|
||||
|
||||
// Pink Types
|
||||
'pink' => '255|192|203',
|
||||
'lightpink' => '255|182|193',
|
||||
'hotpink' => '255|105|180',
|
||||
'deeppink' => '255|20|147',
|
||||
|
||||
// Purple Types
|
||||
'thistle' => '216|191|216',
|
||||
'plum' => '221|160|221',
|
||||
'violet' => '238|130|238',
|
||||
'orchid' => '218|112|214',
|
||||
'fuchsia' => '255|0|255',
|
||||
'magenta' => '255|0|255',
|
||||
'mediumorchid' => '186|85|211',
|
||||
'mediumpurple' => '147|112|219',
|
||||
'darkviolet' => '148|0|211',
|
||||
'darkorchid' => '153|50|204',
|
||||
'darkmagenta' => '139|0|139',
|
||||
'purple' => '128|0|128',
|
||||
|
||||
// Orange Types
|
||||
'coral' => '255|127|80',
|
||||
'gold' => '255|215|0',
|
||||
'orange' => '255|165|0',
|
||||
'darkorange' => '255|140|0',
|
||||
|
||||
// Brown Types
|
||||
'brown' => '165|42|42',
|
||||
|
||||
// White Types
|
||||
'white' => '255|255|255',
|
||||
'snow' => '255|250|250',
|
||||
'honeydew' => '240|255|240',
|
||||
'mintcream' => '245|255|250',
|
||||
'azure' => '240|255|255',
|
||||
'ghostwhite' => '248|248|255',
|
||||
'whitesmoke' => '245|245|245',
|
||||
'seashell' => '255|245|238',
|
||||
'beige' => '245|245|220',
|
||||
'oldlace' => '253|245|230',
|
||||
'floralwhite' => '255|250|240',
|
||||
'ivory' => '255|255|240',
|
||||
'antiquewhite' => '250|235|215',
|
||||
'linen' => '250|240|230'
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,403 @@
|
||||
<?php namespace ZN\Image;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
use stdClass;
|
||||
use ZN\Base;
|
||||
use ZN\Request;
|
||||
use ZN\Filesystem;
|
||||
|
||||
class Render implements RenderInterface
|
||||
{
|
||||
/**
|
||||
* Thumbs directory name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $dirName = 'thumbs';
|
||||
|
||||
/**
|
||||
* Keeps file path
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $file;
|
||||
|
||||
/**
|
||||
* Thumb file path
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $thumbPath;
|
||||
|
||||
/**
|
||||
* Clean thumb files
|
||||
*
|
||||
* @param string $ile
|
||||
* @param bool $origin = false
|
||||
*/
|
||||
public function cleaner(string $path, bool $origin = false)
|
||||
{
|
||||
ThumbCleaner::clean($this->cleanURLFix($path), $origin, $this->dirName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get prosize
|
||||
*
|
||||
* @param string $path
|
||||
* @param int $width = 0
|
||||
* @param int $height = 0
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
public function getProsize(string $path, int $width = 0, int $height = 0) : stdClass
|
||||
{
|
||||
# If the image file is not found, an exception is thrown.
|
||||
$this->throwExceptionImageFileIfNotExists($path);
|
||||
|
||||
# Get image size.
|
||||
$getImageCoordinate = getimagesize($path);
|
||||
|
||||
# It gives the width and height value proportional to the width value of the picture.
|
||||
$x = $getImageCoordinate[0];
|
||||
$y = $getImageCoordinate[1];
|
||||
|
||||
CoordinateRateCalculator::run($width, $x, $y);
|
||||
|
||||
# It gives the width and height value proportional to the height value of the picture.
|
||||
CoordinateRateCalculator::run($height, $x, $y);
|
||||
|
||||
# Return width & height
|
||||
return (object)
|
||||
[
|
||||
'width' => round($x),
|
||||
'height' => round($y)
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Thumb
|
||||
*
|
||||
* @param string $fpath
|
||||
* @param array $set
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function thumb(string $fpath, array $set) : string
|
||||
{
|
||||
# Image origin (x, y).
|
||||
$origin = [0, 0];
|
||||
|
||||
# If the image file is not found, an exception is thrown.
|
||||
$this->throwExceptionImageFileIfNotExists($filePath = $this->cleanURLFix($fpath));
|
||||
|
||||
# If the image type cannot be created, it returns empty.
|
||||
if( ! $createNewImageByType = ImageTypeCreator::from($filePath) )
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
# It extracts the settings made on the image as variables.
|
||||
extract($this->extractSettingVariables($fpath, $set));
|
||||
|
||||
$this->setThumbPaths($filePath);
|
||||
|
||||
# If the Thumb array does not exist, it is created.
|
||||
$this->createThumbDirectoryIfNotExists();
|
||||
|
||||
# Gets the path information of the new formatted file.
|
||||
$getThumbFilePath = $this->getThumbFilePath($this->getThumbFileName($x, $y, $width, $height));
|
||||
|
||||
# If the same operation is applied before, the image is not rebuilt.
|
||||
# It checks to see if there is an image refresh request.
|
||||
# If the same output was previously output, no re-creation is performed.
|
||||
if( ! $this->isRefreshThumbImageCreation($set['refresh'] ?? NULL) && $this->isThumbFileExists($getThumbFilePath) )
|
||||
{
|
||||
return $this->getThumbFileURL($getThumbFilePath); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
# Fill background with color.
|
||||
if( isset($set['backgroundColor']) )
|
||||
{
|
||||
$createNewImage = imagecreatetruecolor($set['backgroundOriginX'], $set['backgroundOriginY']);
|
||||
|
||||
$allocateParameters = explode('|', $set['backgroundColor']);
|
||||
$imageColorAllocate = count($allocateParameters) === 3 ? 'imagecolorallocate' : 'imagecolorallocatealpha';
|
||||
$color = $imageColorAllocate($createNewImage, ...$allocateParameters);
|
||||
|
||||
imagefill($createNewImage, 0, 0, $color);
|
||||
|
||||
$origin = WatermarkImageAligner::align($set['backgroundAlign'], $width, $height, $set['backgroundOriginX'], $set['backgroundOriginY'], 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
# Create a new true color image.
|
||||
$createNewImage = imagecreatetruecolor($width, $height);
|
||||
|
||||
# If the extension of the image file is png, the background is transparent.
|
||||
if( $this->isPNGExtension($filePath) )
|
||||
{
|
||||
$this->applyBackgroundTransparency($createNewImage, $width, $height);
|
||||
}
|
||||
}
|
||||
|
||||
# Copy and resize part of an image with resampling.
|
||||
imagecopyresampled($createNewImage, $createNewImageByType, $origin[0], $origin[1], $x, $y, $width, $height, $rWidth, $rHeight);
|
||||
|
||||
# Creating a new image based on the file type.
|
||||
ImageTypeCreator::create($createNewImage, $getThumbFilePath, $quality);
|
||||
|
||||
# Applies watermark filter if exists.
|
||||
self::addWatermarkFilterIfExists($set, $width, $height);
|
||||
|
||||
# Applies the used filters belonging to the GD class.
|
||||
GDFilter::apply($getThumbFilePath, $set['filters'] ?? NULL);
|
||||
|
||||
# The created images are being deleted.
|
||||
$this->deleteCreatedImages($createNewImageByType, $createNewImage);
|
||||
|
||||
# The new image path is returned from the URL type.
|
||||
return $this->getThumbFileURL($getThumbFilePath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected add watermark filter
|
||||
*/
|
||||
protected function addWatermarkFilterIfExists(&$set, $width, $height)
|
||||
{
|
||||
if( isset($set['watermark']) )
|
||||
{
|
||||
if( ! empty($set['watermark'][1]))
|
||||
{
|
||||
$set['filters'][] = ['target', [$set['watermark'][1]]];
|
||||
}
|
||||
|
||||
if( ! empty($set['watermark'][2]))
|
||||
{
|
||||
$set['filters'][] = ['margin', [$set['watermark'][2]]]; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
$set['filters'][] = ['mix', [$set['watermark'][0]]];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected throw exception image file if not exists
|
||||
*/
|
||||
protected function throwExceptionImageFileIfNotExists($file)
|
||||
{
|
||||
if( ! file_exists($file) )
|
||||
{
|
||||
throw new Exception\ImageNotFoundException(NULL, $file);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected delete created images
|
||||
*/
|
||||
protected function deleteCreatedImages(...$images)
|
||||
{
|
||||
foreach( $images as $image )
|
||||
{
|
||||
imagedestroy($image);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected get thumb file url
|
||||
*/
|
||||
protected function getThumbFileURL($file)
|
||||
{
|
||||
return Request::getBaseURL($file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected is thumb file exists
|
||||
*/
|
||||
protected function isThumbFileExists($file)
|
||||
{
|
||||
return file_exists($file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected is refresh thumb image creation
|
||||
*/
|
||||
protected function isRefreshThumbImageCreation($isRefresh)
|
||||
{
|
||||
return $isRefresh === true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected get thumb file path
|
||||
*/
|
||||
protected function getThumbFilePath($file)
|
||||
{
|
||||
return $this->thumbPath . $file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected get thumb file name
|
||||
*/
|
||||
protected function getThumbFileName($x, $y, $width, $height)
|
||||
{
|
||||
return Filesystem::removeExtension($this->file) .
|
||||
$this->addPrefixToThumbFileName($x, $y, $width, $height) .
|
||||
Filesystem::getExtension($this->file, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected add prefix to thumb file name
|
||||
*/
|
||||
protected function addPrefixToThumbFileName($x, $y, $width, $height)
|
||||
{
|
||||
return '-' . $x . 'x' . $y . 'px-' . $width . 'x' . $height . 'size';
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected create thumb directory if not exists
|
||||
*/
|
||||
protected function createThumbDirectoryIfNotExists()
|
||||
{
|
||||
if( ! is_dir($this->thumbPath) )
|
||||
{
|
||||
mkdir($this->thumbPath);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected is png extension
|
||||
*/
|
||||
protected function isPNGExtension($file)
|
||||
{
|
||||
return Filesystem::getExtension($file) === 'png';
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected apply bacground transparency
|
||||
*/
|
||||
protected function applyBackgroundTransparency($file, $width, $height)
|
||||
{
|
||||
imagealphablending($file, false);
|
||||
imagesavealpha($file, true);
|
||||
imagefilledrectangle($file, 0, 0, $width, $height, $this->transparentBackground($file));
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected transparent background
|
||||
*/
|
||||
protected function transparentBackground($file)
|
||||
{
|
||||
return imagecolorallocatealpha($file, 255, 255, 255, 127);
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected New Path
|
||||
*/
|
||||
protected function setThumbPaths($file)
|
||||
{
|
||||
$this->file = $this->getOnlyFileName($file);
|
||||
$this->thumbPath = $this->createThumbDirectory($file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected get only file name
|
||||
*/
|
||||
protected function getOnlyFileName($file)
|
||||
{
|
||||
return pathinfo($file, PATHINFO_BASENAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected get only directory name
|
||||
*/
|
||||
protected function getFileDirectory($file, $thumb = NULL)
|
||||
{
|
||||
return pathinfo($file, PATHINFO_DIRNAME) . '/';
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected get thumb directory name
|
||||
*/
|
||||
protected function getThumbDirectoryName()
|
||||
{
|
||||
return Base::suffix($this->dirName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected clean url fix
|
||||
*/
|
||||
protected function cleanURLFix($path)
|
||||
{
|
||||
return Base::removePrefix($path, Request::getBaseURL());
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected create thumb directory
|
||||
*/
|
||||
protected function createThumbDirectory($file)
|
||||
{
|
||||
return $this->cleanURLFix($this->getFileDirectory($file) . $this->getThumbDirectoryName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected extract setting variables
|
||||
*/
|
||||
protected function extractSettingVariables($file, $settings)
|
||||
{
|
||||
$variables = [];
|
||||
|
||||
list($currentWidth, $currentHeight) = getimagesize($file);
|
||||
|
||||
$variables['currentWidth'] = $currentWidth;
|
||||
$variables['currentHeight'] = $currentHeight;
|
||||
$variables['x'] = $settings['x'] ?? 0;
|
||||
$variables['y'] = $settings['y'] ?? 0;
|
||||
$variables['quality'] = $settings['quality'] ?? 0;
|
||||
$variables['prowidth'] = $settings['prowidth'] ?? NULL;
|
||||
$variables['proheight'] = $settings['proheight'] ?? NULL;
|
||||
$rewidth = $settings['width'] ?? $currentWidth;
|
||||
$reheight = $settings['height'] ?? $currentHeight;
|
||||
|
||||
# Resizes the height value.
|
||||
if( ! empty($settings['reheight' ]) )
|
||||
{
|
||||
$height = $settings['reheight'];
|
||||
}
|
||||
# It gives the width and height value proportional to the height value of the picture.
|
||||
elseif( ! empty($settings['proheight']) && $settings['proheight'] < $currentHeight )
|
||||
{
|
||||
$height = $settings['proheight'];
|
||||
$width = round(($currentWidth * $height) / $currentHeight);
|
||||
}
|
||||
|
||||
# Resizes the width value.
|
||||
if( ! empty($settings['rewidth' ]) )
|
||||
{
|
||||
$width = $settings['rewidth' ];
|
||||
}
|
||||
# It gives the width and height value proportional to the width value of the picture.
|
||||
elseif( ! empty($settings['prowidth']) && $settings['prowidth'] < $currentWidth )
|
||||
{
|
||||
$width = $settings['prowidth'];
|
||||
$height = round(($currentHeight * $width) / $currentWidth);
|
||||
}
|
||||
|
||||
# Gets width and height value information.
|
||||
$variables['width' ] = $width ?? $rewidth;
|
||||
$variables['height'] = $height ?? $reheight;
|
||||
|
||||
# The black portions are cut off.
|
||||
$variables['rWidth'] = $rewidth - $variables['x'];
|
||||
$variables['rHeight'] = $reheight - $variables['y'];
|
||||
|
||||
# Return setting variables.
|
||||
return $variables;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php namespace ZN\Image;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
use stdClass;
|
||||
|
||||
interface RenderInterface
|
||||
{
|
||||
/**
|
||||
* Clean thumb files
|
||||
*
|
||||
* @param string $ile
|
||||
* @param bool $origin = false
|
||||
*/
|
||||
public function cleaner(string $path, bool $origin = false);
|
||||
|
||||
/**
|
||||
* Get prosize
|
||||
*
|
||||
* @param string $path
|
||||
* @param int $width = 0
|
||||
* @param int $height = 0
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
public function getProsize(string $path, int $width = 0, int $height = 0) : stdClass;
|
||||
|
||||
/**
|
||||
* Thumb
|
||||
*
|
||||
* @param string $fpath
|
||||
* @param array $set
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function thumb(string $fpath, array $set) : string;
|
||||
}
|
||||
@@ -0,0 +1,231 @@
|
||||
<?php namespace ZN\Image;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
use ZN\Base;
|
||||
use ZN\Request;
|
||||
use ZN\Singleton;
|
||||
|
||||
class Thumb implements ThumbInterface
|
||||
{
|
||||
use CallableFilters;
|
||||
|
||||
/**
|
||||
* Keeps settings
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $sets;
|
||||
|
||||
/**
|
||||
* Keeps render class
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
protected $image;
|
||||
|
||||
/**
|
||||
* Magic Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->image = Singleton::class('ZN\Image\Render');
|
||||
}
|
||||
|
||||
/**
|
||||
* Watermark.
|
||||
*
|
||||
* @return Thumb
|
||||
*/
|
||||
public function watermark(string $source, ?string $align = NULL, $margin = 0) : Thumb
|
||||
{
|
||||
$this->sets['watermark'] = [Base::removePrefix($source, Request::getBaseURL()), $align, $margin];
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets fill background
|
||||
*
|
||||
* @param int $x
|
||||
* @param int $y
|
||||
* @param string $color = 'white'
|
||||
* @param string $align = 'center'
|
||||
*
|
||||
* @return Thumb
|
||||
*/
|
||||
public function background(int $x, int $y, string $color = 'white', string $align = 'center') : Thumb
|
||||
{
|
||||
$this->sets['backgroundOriginX'] = $x;
|
||||
$this->sets['backgroundOriginY'] = $y;
|
||||
$this->sets['backgroundColor'] = ColorConverter::run($color);
|
||||
$this->sets['backgroundAlign'] = $align;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh image filtering.
|
||||
*
|
||||
* @return Thumb
|
||||
*/
|
||||
public function refresh() : Thumb
|
||||
{
|
||||
$this->sets['refresh'] = true;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets file path
|
||||
*
|
||||
* @param string $file
|
||||
*
|
||||
* @return Thumb
|
||||
*/
|
||||
public function path(string $file) : Thumb
|
||||
{
|
||||
$this->sets['filePath'] = $file;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets image quality
|
||||
*
|
||||
* @param int $quality
|
||||
*
|
||||
* @return Thumb
|
||||
*/
|
||||
public function quality(int $quality) : Thumb
|
||||
{
|
||||
$this->sets['quality'] = $quality;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Crop image
|
||||
*
|
||||
* @param int $x
|
||||
* @param int $y
|
||||
*
|
||||
* @return Thumb
|
||||
*/
|
||||
public function crop(int $x, int $y) : Thumb
|
||||
{
|
||||
$this->sets['x'] = $x;
|
||||
$this->sets['y'] = $y;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets image size
|
||||
*
|
||||
* @param int $width
|
||||
* @param int $height
|
||||
*
|
||||
* @return Thumb
|
||||
*/
|
||||
public function size(int $width, int $height) : Thumb
|
||||
{
|
||||
$this->sets['width'] = $width;
|
||||
$this->sets['height'] = $height;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets image resize
|
||||
*
|
||||
* @param int $width
|
||||
* @param int $height
|
||||
*
|
||||
* @return Thumb
|
||||
*/
|
||||
public function resize(int $width, int $height) : Thumb
|
||||
{
|
||||
$this->sets['rewidth'] = $width;
|
||||
$this->sets['reheight'] = $height;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets image proportional size
|
||||
*
|
||||
* @param int $width
|
||||
* @param int $height
|
||||
*
|
||||
* @return Thumb
|
||||
*/
|
||||
public function prosize(int $width, int $height = 0) : Thumb
|
||||
{
|
||||
$this->sets['prowidth'] = $width;
|
||||
$this->sets['proheight'] = $height;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new image
|
||||
*
|
||||
* @param string $path = NULL
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function create(?string $path = NULL) : string
|
||||
{
|
||||
if( isset($this->sets['filePath']) )
|
||||
{
|
||||
$path = $this->sets['filePath'];
|
||||
}
|
||||
|
||||
# It keeps the used filters belonging to the GD class.
|
||||
# [5.7.8]added
|
||||
$this->sets['filters'] = $this->filters;
|
||||
|
||||
$settings = $this->sets;
|
||||
|
||||
$this->sets = [];
|
||||
|
||||
return $this->image->thumb($path, $settings);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get proportional size
|
||||
*
|
||||
* @param int $width = 0
|
||||
* @param int $height = 0
|
||||
*
|
||||
* @return object|false
|
||||
*/
|
||||
public function getProsize(int $width = 0, int $height = 0)
|
||||
{
|
||||
if( ! isset($this->sets['filePath']) )
|
||||
{
|
||||
return false; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
return $this->image->getProsize($this->sets['filePath'], $width, $height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean thumb files
|
||||
*
|
||||
* @param string $ile
|
||||
* @param bool $origin = false
|
||||
*/
|
||||
public function clean(string $path, bool $origin = false)
|
||||
{
|
||||
$this->image->cleaner($path, $origin);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php namespace ZN\Image;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
use ZN\Filesystem;
|
||||
|
||||
class ThumbCleaner
|
||||
{
|
||||
/**
|
||||
* Clean thumb files
|
||||
*
|
||||
* @param string $ile
|
||||
* @param bool $origin = false
|
||||
* @param string $path = NULL
|
||||
*/
|
||||
public static function clean(string $file, bool $origin = false, ?string $path = NULL)
|
||||
{
|
||||
if( is_file($file) )
|
||||
{
|
||||
$dir = pathinfo($file, PATHINFO_DIRNAME);
|
||||
$filename = pathinfo($file, PATHINFO_FILENAME);
|
||||
|
||||
if( is_dir($directory = $dir . '/' . $path . '/') )
|
||||
{
|
||||
if( $files = preg_grep('/^' . preg_quote($filename) . '/', Filesystem::getFiles($directory)) )
|
||||
{
|
||||
foreach( $files as $thumbFile )
|
||||
{
|
||||
unlink($directory . $thumbFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( $origin === true )
|
||||
{
|
||||
unlink($file); // @codeCoverageIgnore
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
<?php namespace ZN\Image;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
interface ThumbInterface
|
||||
{
|
||||
/**
|
||||
* Sets fill background
|
||||
*
|
||||
* @param int $x
|
||||
* @param int $y
|
||||
* @param string $color = 'white'
|
||||
* @param string $align = 'center'
|
||||
*
|
||||
* @return Thumb
|
||||
*/
|
||||
public function background(int $x, int $y, string $color = 'white', string $align = 'center') : Thumb;
|
||||
|
||||
/**
|
||||
* Watermark.
|
||||
*
|
||||
* @return Thumb
|
||||
*/
|
||||
public function watermark(string $source, ?string $align = NULL, $margin = 0) : Thumb;
|
||||
|
||||
/**
|
||||
* Refresh image filtering.
|
||||
*
|
||||
* @return Thumb
|
||||
*/
|
||||
public function refresh() : Thumb;
|
||||
|
||||
/**
|
||||
* Sets file path
|
||||
*
|
||||
* @param string $file
|
||||
*
|
||||
* @return Thumb
|
||||
*/
|
||||
public function path(string $file) : Thumb;
|
||||
|
||||
/**
|
||||
* Sets image quality
|
||||
*
|
||||
* @param int $quality
|
||||
*
|
||||
* @return Thumb
|
||||
*/
|
||||
public function quality(int $quality) : Thumb;
|
||||
|
||||
/**
|
||||
* Crop image
|
||||
*
|
||||
* @param int $x
|
||||
* @param int $y
|
||||
*
|
||||
* @return Thumb
|
||||
*/
|
||||
public function crop(int $x, int $y) : Thumb;
|
||||
|
||||
/**
|
||||
* Sets image size
|
||||
*
|
||||
* @param int $width
|
||||
* @param int $height
|
||||
*
|
||||
* @return Thumb
|
||||
*/
|
||||
public function size(int $width, int $height) : Thumb;
|
||||
|
||||
/**
|
||||
* Sets image resize
|
||||
*
|
||||
* @param int $width
|
||||
* @param int $height
|
||||
*
|
||||
* @return Thumb
|
||||
*/
|
||||
public function resize(int $width, int $height) : Thumb;
|
||||
|
||||
/**
|
||||
* Sets image proportional size
|
||||
*
|
||||
* @param int $width
|
||||
* @param int $height
|
||||
*
|
||||
* @return Thumb
|
||||
*/
|
||||
public function prosize(int $width, int $height = 0) : Thumb;
|
||||
|
||||
/**
|
||||
* Create new image
|
||||
*
|
||||
* @param string $path = NULL
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function create(string $path) : string;
|
||||
|
||||
/**
|
||||
* Get proportional size
|
||||
*
|
||||
* @param int $width = 0
|
||||
* @param int $height = 0
|
||||
*
|
||||
* @return object|false
|
||||
*/
|
||||
public function getProsize(int $width, int $height);
|
||||
|
||||
/**
|
||||
* Clean thumb files
|
||||
*
|
||||
* @param string $ile
|
||||
* @param bool $origin = false
|
||||
*/
|
||||
public function clean(string $path, bool $origin = false);
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
<?php namespace ZN\Image;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
class WatermarkImageAligner
|
||||
{
|
||||
/**
|
||||
* It forms the alignment values according to conformation.
|
||||
*
|
||||
* @param string $type - options
|
||||
* [
|
||||
* topleft |topcenter |topright
|
||||
* middleleft|center |middleright
|
||||
* bottomleft|bottomcenter|bottomright
|
||||
* ]
|
||||
* @param string $sourceWidth
|
||||
* @param string $sourceHeight
|
||||
* @param string $targetWidth
|
||||
* @param string $targetHeight
|
||||
* @param int $margin
|
||||
*
|
||||
* @return array - [x, y]
|
||||
*/
|
||||
public static function align($type, $swidth, $sheight, $twidth, $theight, $margin)
|
||||
{
|
||||
switch( strtolower($type) )
|
||||
{
|
||||
case 'center':
|
||||
{
|
||||
$x = self::alignCenter($twidth , $swidth);
|
||||
$y = self::alignCenter($theight, $sheight);
|
||||
}
|
||||
break;
|
||||
case 'topleft':
|
||||
{
|
||||
$x = $margin;
|
||||
$y = $margin;
|
||||
}
|
||||
break;
|
||||
case 'topcenter':
|
||||
{
|
||||
$x = self::alignCenter($twidth , $swidth);
|
||||
$y = $margin;
|
||||
}
|
||||
break;
|
||||
case 'topright':
|
||||
{
|
||||
$x = self::alignEdge($twidth, $swidth, -$margin);
|
||||
$y = $margin;
|
||||
}
|
||||
break;
|
||||
case 'middleleft':
|
||||
{
|
||||
$x = $margin;
|
||||
$y = self::alignCenter($theight, $sheight);
|
||||
}
|
||||
break;
|
||||
case 'middleright':
|
||||
{
|
||||
$x = self::alignEdge($twidth, $swidth, -$margin);
|
||||
$y = self::alignCenter($theight, $sheight);
|
||||
}
|
||||
break;
|
||||
case 'bottomleft':
|
||||
{
|
||||
$x = $margin;
|
||||
$y = self::alignEdge($theight, $sheight, -$margin);
|
||||
}
|
||||
break;
|
||||
case 'bottomcenter':
|
||||
{
|
||||
$x = self::alignCenter($twidth, $swidth);
|
||||
$y = self::alignEdge($theight, $sheight, -$margin);
|
||||
}
|
||||
break;
|
||||
case 'bottomright':
|
||||
{
|
||||
$x = self::alignEdge($twidth , $swidth , -$margin);
|
||||
$y = self::alignEdge($theight, $sheight, -$margin);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return [$x, $y];
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected align left
|
||||
*/
|
||||
protected static function alignEdge($val1, $val2, $margin)
|
||||
{
|
||||
return $val1 - $val2 + $margin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected align center
|
||||
*/
|
||||
protected static function alignCenter($val1, $val2)
|
||||
{
|
||||
return ($val1 / 2) - ($val2 / 2);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user