Регистр файлов

This commit is contained in:
origami11 2017-02-16 10:14:36 +03:00
parent 4fd0187ea6
commit c8958cbee0
83 changed files with 25 additions and 53 deletions

40
src/Tools/Image.php Normal file
View file

@ -0,0 +1,40 @@
<?php
class Core_Tools_Image
{
static function load($uri)
{
$e = strtolower(pathinfo($uri, PATHINFO_EXTENSION));
switch ($e) {
case 'png': return imagecreatefrompng($uri);
case 'jpeg': case 'jpg': return imagecreatefromjpeg($uri);
case 'gif': return imagecreatefromgif($uri);
}
}
static function fit($image, $prewidth, $preheight, $force = true)
{
$width = imagesx($image);
$height = imagesy($image);
$percent = min($prewidth / $width, $preheight / $height);
if ($percent > 1 && !$force) $percent = 1;
$new_width = $width * $percent;
$new_height = $height * $percent;
$image_p = imagecreatetruecolor($new_width, $new_height);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
return $image_p;
}
static function save($image, $uri)
{
$e = strtolower(pathinfo($uri, PATHINFO_EXTENSION));
switch ($e) {
case 'jpg': imagejpeg($image, $uri, 100); break;
case 'png': imagepng($image, $uri); break;
case 'gif': imagegif($image, $uri); break;
}
}
}