1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* UPLOAD |
5
|
|
|
*/ |
6
|
|
|
define("CONF_UPLOAD_DIR", "uploads"); |
7
|
|
|
define("CONF_UPLOAD_IMAGE_DIR", "images"); |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* IMAGES |
12
|
|
|
*/ |
13
|
|
|
define("CONF_IMAGE_CACHE", CONF_UPLOAD_DIR . "/" . CONF_UPLOAD_IMAGE_DIR . "/cache"); |
14
|
|
|
define("CONF_IMAGE_QUALITY", ["jpg" => 75, "png" => 5]); |
15
|
|
|
|
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* AUTOLOAD |
19
|
|
|
*/ |
20
|
|
|
$baseDir = dirname(__FILE__); |
21
|
|
|
$libDir = $baseDir . '/vendor'; |
22
|
|
|
$vendorDir = dirname(dirname($baseDir)); |
23
|
|
|
$autoload = '/autoload.php'; |
24
|
|
|
|
25
|
|
|
if (!class_exists('whallysson\Thumb')) { |
26
|
|
|
if (file_exists($libDir . $autoload)) { |
27
|
|
|
require_once $libDir . $autoload; |
28
|
|
|
} elseif (file_exists($vendorDir . $autoload)) { |
29
|
|
|
require_once $vendorDir . $autoload; |
30
|
|
|
} else { |
31
|
|
|
require_once $baseDir . '/src/Thumb.php'; |
32
|
|
|
} |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** Função para gerar imagens */ |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param string $image |
39
|
|
|
* @param int $width |
40
|
|
|
* @param int|null $height |
41
|
|
|
* @param int|null $zc |
42
|
|
|
* @return string |
43
|
|
|
*/ |
44
|
|
|
function image($image, $width, $height = null, $zc = null, $imageName = null) |
45
|
|
|
{ |
46
|
|
|
if ($image) { |
47
|
|
|
$newimage = (new \whallysson\Thumb())->make($image, $width, $height, $zc, $imageName); |
48
|
|
|
|
49
|
|
|
/** WEBP */ |
50
|
|
|
$newName = ($imageName ? $imageName : pathinfo(filter_var(mb_strtolower($newimage), |
51
|
|
|
FILTER_SANITIZE_STRIPPED))['filename']); |
52
|
|
|
$destination = "{$newName}-{$width}.webp"; |
53
|
|
|
|
54
|
|
|
$webp = new \CodeBlog\ToWebP\ToWebP(CONF_UPLOAD_DIR, CONF_UPLOAD_IMAGE_DIR . "/cache"); |
55
|
|
|
$webp->convert($newimage, $destination); |
56
|
|
|
|
57
|
|
|
return (!empty($webp->image_webp) ? $webp->image_webp : $webp->image_original); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
return null; |
61
|
|
|
} |
62
|
|
|
|