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