Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/wp-conte.../plugins/smart-sl.../Nextend/Framewor.../Image
File: ImageEdit.php
<?php
[0] Fix | Delete
[1] Fix | Delete
[2] Fix | Delete
namespace Nextend\Framework\Image;
[3] Fix | Delete
[4] Fix | Delete
[5] Fix | Delete
use Exception;
[6] Fix | Delete
use Nextend\Framework\Cache\CacheImage;
[7] Fix | Delete
use Nextend\Framework\Filesystem\Filesystem;
[8] Fix | Delete
use Nextend\Framework\Misc\Base64;
[9] Fix | Delete
use Nextend\Framework\Parser\Color;
[10] Fix | Delete
use Nextend\Framework\ResourceTranslator\ResourceTranslator;
[11] Fix | Delete
use Nextend\Framework\Url\Url;
[12] Fix | Delete
[13] Fix | Delete
class ImageEdit {
[14] Fix | Delete
[15] Fix | Delete
public static function resizeImage($group, $imageUrlOrPath, $targetWidth, $targetHeight, $lazy = false, $mode = 'cover', $backgroundColor = false, $resizeRemote = false, $quality = 100, $optimize = false, $x = 50, $y = 50) {
[16] Fix | Delete
[17] Fix | Delete
if (strpos($imageUrlOrPath, Filesystem::getBasePath()) === 0) {
[18] Fix | Delete
$imageUrl = Url::pathToUri($imageUrlOrPath);
[19] Fix | Delete
} else {
[20] Fix | Delete
$imageUrl = ResourceTranslator::toUrl(ResourceTranslator::pathToResource($imageUrlOrPath));
[21] Fix | Delete
}
[22] Fix | Delete
[23] Fix | Delete
if (!extension_loaded('gd') || $targetWidth <= 0 || $targetHeight <= 0) {
[24] Fix | Delete
return $imageUrl;
[25] Fix | Delete
}
[26] Fix | Delete
[27] Fix | Delete
$quality = max(0, min(100, $quality));
[28] Fix | Delete
$originalImageUrl = $imageUrl;
[29] Fix | Delete
[30] Fix | Delete
if (substr($imageUrl, 0, 2) == '//') {
[31] Fix | Delete
$imageUrl = parse_url(Url::getFullUri(), PHP_URL_SCHEME) . ':' . $imageUrl;
[32] Fix | Delete
}
[33] Fix | Delete
[34] Fix | Delete
$imageUrl = Url::relativetoabsolute($imageUrl);
[35] Fix | Delete
$imagePath = Filesystem::absoluteURLToPath($imageUrl);
[36] Fix | Delete
[37] Fix | Delete
$cache = new CacheImage($group);
[38] Fix | Delete
if ($lazy) {
[39] Fix | Delete
$cache->setLazy(true);
[40] Fix | Delete
}
[41] Fix | Delete
[42] Fix | Delete
if ($imagePath == $imageUrl) {
[43] Fix | Delete
// The image is not local
[44] Fix | Delete
if (!$resizeRemote) {
[45] Fix | Delete
return $originalImageUrl;
[46] Fix | Delete
}
[47] Fix | Delete
[48] Fix | Delete
$pathInfo = pathinfo(parse_url($imageUrl, PHP_URL_PATH));
[49] Fix | Delete
$extension = false;
[50] Fix | Delete
if (isset($pathInfo['extension'])) {
[51] Fix | Delete
$extension = self::validateGDExtension($pathInfo['extension']);
[52] Fix | Delete
}
[53] Fix | Delete
[54] Fix | Delete
$extension = self::checkMetaExtension($originalImageUrl, $extension);
[55] Fix | Delete
[56] Fix | Delete
if (!$extension) {
[57] Fix | Delete
return $originalImageUrl;
[58] Fix | Delete
}
[59] Fix | Delete
[60] Fix | Delete
if (strtolower($extension) === 'webp' && !function_exists('imagecreatefromwebp')) {
[61] Fix | Delete
return $originalImageUrl;
[62] Fix | Delete
}
[63] Fix | Delete
[64] Fix | Delete
$resizedPath = $cache->makeCache($extension, array(
[65] Fix | Delete
self::class,
[66] Fix | Delete
'_resizeRemoteImage'
[67] Fix | Delete
), array(
[68] Fix | Delete
$extension,
[69] Fix | Delete
$imageUrl,
[70] Fix | Delete
$targetWidth,
[71] Fix | Delete
$targetHeight,
[72] Fix | Delete
$mode,
[73] Fix | Delete
$backgroundColor,
[74] Fix | Delete
$quality,
[75] Fix | Delete
$optimize,
[76] Fix | Delete
$x,
[77] Fix | Delete
$y
[78] Fix | Delete
));
[79] Fix | Delete
[80] Fix | Delete
if (substr($resizedPath, 0, 5) == 'http:' || substr($resizedPath, 0, 6) == 'https:') {
[81] Fix | Delete
return $resizedPath;
[82] Fix | Delete
}
[83] Fix | Delete
[84] Fix | Delete
if ($resizedPath === $originalImageUrl) {
[85] Fix | Delete
return $originalImageUrl;
[86] Fix | Delete
}
[87] Fix | Delete
[88] Fix | Delete
return Filesystem::pathToAbsoluteURL($resizedPath);
[89] Fix | Delete
[90] Fix | Delete
} else {
[91] Fix | Delete
$extension = false;
[92] Fix | Delete
$imageType = @self::exif_imagetype($imagePath);
[93] Fix | Delete
switch ($imageType) {
[94] Fix | Delete
case IMAGETYPE_JPEG:
[95] Fix | Delete
$extension = 'jpg';
[96] Fix | Delete
break;
[97] Fix | Delete
case IMAGETYPE_PNG:
[98] Fix | Delete
if (self::isPNG8($imagePath)) {
[99] Fix | Delete
// GD cannot resize palette PNG so we return the original image
[100] Fix | Delete
return $originalImageUrl;
[101] Fix | Delete
}
[102] Fix | Delete
$extension = 'png';
[103] Fix | Delete
break;
[104] Fix | Delete
case IMAGETYPE_WEBP:
[105] Fix | Delete
if (!function_exists('imagecreatefromwebp')) {
[106] Fix | Delete
return $originalImageUrl;
[107] Fix | Delete
}
[108] Fix | Delete
$extension = 'webp';
[109] Fix | Delete
break;
[110] Fix | Delete
}
[111] Fix | Delete
if (!$extension) {
[112] Fix | Delete
return $originalImageUrl;
[113] Fix | Delete
}
[114] Fix | Delete
[115] Fix | Delete
return Filesystem::pathToAbsoluteURL($cache->makeCache($extension, array(
[116] Fix | Delete
self::class,
[117] Fix | Delete
'_resizeImage'
[118] Fix | Delete
), array(
[119] Fix | Delete
$extension,
[120] Fix | Delete
$imagePath,
[121] Fix | Delete
$targetWidth,
[122] Fix | Delete
$targetHeight,
[123] Fix | Delete
$mode,
[124] Fix | Delete
$backgroundColor,
[125] Fix | Delete
$quality,
[126] Fix | Delete
$optimize,
[127] Fix | Delete
$x,
[128] Fix | Delete
$y
[129] Fix | Delete
)));
[130] Fix | Delete
}
[131] Fix | Delete
}
[132] Fix | Delete
[133] Fix | Delete
public static function _resizeRemoteImage($targetFile, $extension, $imageUrl, $targetWidth, $targetHeight, $mode, $backgroundColor, $quality, $optimize, $x, $y) {
[134] Fix | Delete
return self::_resizeImage($targetFile, $extension, $imageUrl, $targetWidth, $targetHeight, $mode, $backgroundColor, $quality, $optimize, $x, $y);
[135] Fix | Delete
}
[136] Fix | Delete
[137] Fix | Delete
public static function _resizeImage($targetFile, $extension, $imagePath, $targetWidth, $targetHeight, $mode, $backgroundColor, $quality = 100, $optimize = false, $x = 50, $y = 50) {
[138] Fix | Delete
$targetDir = dirname($targetFile);
[139] Fix | Delete
[140] Fix | Delete
$rotated = false;
[141] Fix | Delete
[142] Fix | Delete
if ($extension == 'png') {
[143] Fix | Delete
$image = @imagecreatefrompng($imagePath);
[144] Fix | Delete
} else if ($extension == 'jpg') {
[145] Fix | Delete
$image = @imagecreatefromjpeg($imagePath);
[146] Fix | Delete
if (function_exists("exif_read_data")) {
[147] Fix | Delete
$exif = @exif_read_data($imagePath);
[148] Fix | Delete
[149] Fix | Delete
$rotated = self::getOrientation($exif, $image);
[150] Fix | Delete
if ($rotated) {
[151] Fix | Delete
imagedestroy($image);
[152] Fix | Delete
$image = $rotated;
[153] Fix | Delete
}
[154] Fix | Delete
}
[155] Fix | Delete
} else if ($extension == 'webp') {
[156] Fix | Delete
//@TODO: should we need to care about rotation?
[157] Fix | Delete
$image = @imagecreatefromwebp($imagePath);
[158] Fix | Delete
}
[159] Fix | Delete
[160] Fix | Delete
if (isset($image) && $image) {
[161] Fix | Delete
$originalWidth = imagesx($image);
[162] Fix | Delete
$originalHeight = imagesy($image);
[163] Fix | Delete
[164] Fix | Delete
if ($optimize) {
[165] Fix | Delete
if ($originalWidth <= $targetWidth || $originalHeight <= $targetHeight) {
[166] Fix | Delete
if (!Filesystem::existsFolder($targetDir)) {
[167] Fix | Delete
Filesystem::createFolder($targetDir);
[168] Fix | Delete
}
[169] Fix | Delete
if ($extension == 'png') {
[170] Fix | Delete
imagesavealpha($image, true);
[171] Fix | Delete
imagealphablending($image, false);
[172] Fix | Delete
imagepng($image, $targetFile);
[173] Fix | Delete
} else if ($extension == 'jpg') {
[174] Fix | Delete
imagejpeg($image, $targetFile, $quality);
[175] Fix | Delete
} else if ($extension == 'webp') {
[176] Fix | Delete
imagesavealpha($image, true);
[177] Fix | Delete
imagealphablending($image, false);
[178] Fix | Delete
imagewebp($image, $targetFile, $quality);
[179] Fix | Delete
}
[180] Fix | Delete
imagedestroy($image);
[181] Fix | Delete
[182] Fix | Delete
return true;
[183] Fix | Delete
}
[184] Fix | Delete
[185] Fix | Delete
if ($originalWidth / $targetWidth > $originalHeight / $targetHeight) {
[186] Fix | Delete
$targetWidth = round($originalWidth / ($originalHeight / $targetHeight));
[187] Fix | Delete
} else {
[188] Fix | Delete
$targetHeight = round($originalHeight / ($originalWidth / $targetWidth));
[189] Fix | Delete
}
[190] Fix | Delete
}
[191] Fix | Delete
if ($rotated || $originalWidth != $targetWidth || $originalHeight != $targetHeight) {
[192] Fix | Delete
$newImage = imagecreatetruecolor($targetWidth, $targetHeight);
[193] Fix | Delete
if ($extension == 'png' || $extension == 'webp') {
[194] Fix | Delete
imagesavealpha($newImage, true);
[195] Fix | Delete
imagealphablending($newImage, false);
[196] Fix | Delete
$transparent = imagecolorallocatealpha($newImage, 255, 255, 255, 127);
[197] Fix | Delete
imagefilledrectangle($image, 0, 0, $targetWidth, $targetHeight, $transparent);
[198] Fix | Delete
} else if ($extension == 'jpg' && $backgroundColor) {
[199] Fix | Delete
$rgb = Color::hex2rgb($backgroundColor);
[200] Fix | Delete
$background = imagecolorallocate($newImage, $rgb[0], $rgb[1], $rgb[2]);
[201] Fix | Delete
imagefilledrectangle($newImage, 0, 0, $targetWidth, $targetHeight, $background);
[202] Fix | Delete
}
[203] Fix | Delete
[204] Fix | Delete
list($dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h) = self::imageMode($targetWidth, $targetHeight, $originalWidth, $originalHeight, $mode, $x, $y);
[205] Fix | Delete
imagecopyresampled($newImage, $image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
[206] Fix | Delete
imagedestroy($image);
[207] Fix | Delete
[208] Fix | Delete
} else {
[209] Fix | Delete
$newImage = $image;
[210] Fix | Delete
}
[211] Fix | Delete
[212] Fix | Delete
if (!Filesystem::existsFolder($targetDir)) {
[213] Fix | Delete
Filesystem::createFolder($targetDir);
[214] Fix | Delete
}
[215] Fix | Delete
if ($extension == 'png') {
[216] Fix | Delete
imagepng($newImage, $targetFile);
[217] Fix | Delete
} else if ($extension == 'jpg') {
[218] Fix | Delete
imagejpeg($newImage, $targetFile, $quality);
[219] Fix | Delete
} else if ($extension == 'webp') {
[220] Fix | Delete
imagewebp($newImage, $targetFile, $quality);
[221] Fix | Delete
}
[222] Fix | Delete
imagedestroy($newImage);
[223] Fix | Delete
[224] Fix | Delete
return true;
[225] Fix | Delete
}
[226] Fix | Delete
[227] Fix | Delete
throw new Exception('Unable to resize image: ' . $imagePath);
[228] Fix | Delete
}
[229] Fix | Delete
[230] Fix | Delete
public static function scaleImage($group, $imageUrlOrPath, $scale = 1, $resizeRemote = false, $quality = 100) {
[231] Fix | Delete
[232] Fix | Delete
[233] Fix | Delete
if (strpos($imageUrlOrPath, Filesystem::getBasePath()) === 0) {
[234] Fix | Delete
$imageUrl = Url::pathToUri($imageUrlOrPath);
[235] Fix | Delete
} else {
[236] Fix | Delete
$imageUrl = ResourceTranslator::toUrl($imageUrlOrPath);
[237] Fix | Delete
}
[238] Fix | Delete
[239] Fix | Delete
if (!extension_loaded('gd') || $scale <= 0) {
[240] Fix | Delete
return $imageUrl;
[241] Fix | Delete
}
[242] Fix | Delete
[243] Fix | Delete
$quality = max(0, min(100, $quality));
[244] Fix | Delete
$originalImageUrl = $imageUrl;
[245] Fix | Delete
[246] Fix | Delete
if (substr($imageUrl, 0, 2) == '//') {
[247] Fix | Delete
$imageUrl = parse_url(Url::getFullUri(), PHP_URL_SCHEME) . ':' . $imageUrl;
[248] Fix | Delete
}
[249] Fix | Delete
[250] Fix | Delete
$imageUrl = Url::relativetoabsolute($imageUrl);
[251] Fix | Delete
$imagePath = Filesystem::absoluteURLToPath($imageUrl);
[252] Fix | Delete
[253] Fix | Delete
$cache = new CacheImage($group);
[254] Fix | Delete
if ($imagePath == $imageUrl) {
[255] Fix | Delete
// The image is not local
[256] Fix | Delete
if (!$resizeRemote) {
[257] Fix | Delete
return $originalImageUrl;
[258] Fix | Delete
}
[259] Fix | Delete
[260] Fix | Delete
$pathInfo = pathinfo(parse_url($imageUrl, PHP_URL_PATH));
[261] Fix | Delete
$extension = false;
[262] Fix | Delete
if (isset($pathInfo['extension'])) {
[263] Fix | Delete
$extension = self::validateGDExtension($pathInfo['extension']);
[264] Fix | Delete
}
[265] Fix | Delete
[266] Fix | Delete
$extension = self::checkMetaExtension($imageUrl, $extension);
[267] Fix | Delete
[268] Fix | Delete
if (!$extension) {
[269] Fix | Delete
return $originalImageUrl;
[270] Fix | Delete
}
[271] Fix | Delete
[272] Fix | Delete
if (strtolower($extension) === 'webp' && !function_exists('imagecreatefromwebp')) {
[273] Fix | Delete
return $originalImageUrl;
[274] Fix | Delete
}
[275] Fix | Delete
[276] Fix | Delete
return ResourceTranslator::urlToResource(Filesystem::pathToAbsoluteURL($cache->makeCache($extension, array(
[277] Fix | Delete
self::class,
[278] Fix | Delete
'_scaleRemoteImage'
[279] Fix | Delete
), array(
[280] Fix | Delete
$extension,
[281] Fix | Delete
$imageUrl,
[282] Fix | Delete
$scale,
[283] Fix | Delete
$quality
[284] Fix | Delete
))));
[285] Fix | Delete
[286] Fix | Delete
} else {
[287] Fix | Delete
$extension = false;
[288] Fix | Delete
$imageType = @self::exif_imagetype($imagePath);
[289] Fix | Delete
switch ($imageType) {
[290] Fix | Delete
case IMAGETYPE_JPEG:
[291] Fix | Delete
$extension = 'jpg';
[292] Fix | Delete
break;
[293] Fix | Delete
case IMAGETYPE_PNG:
[294] Fix | Delete
if (self::isPNG8($imagePath)) {
[295] Fix | Delete
// GD cannot resize palette PNG so we return the original image
[296] Fix | Delete
return $originalImageUrl;
[297] Fix | Delete
}
[298] Fix | Delete
$extension = 'png';
[299] Fix | Delete
break;
[300] Fix | Delete
case IMAGETYPE_WEBP:
[301] Fix | Delete
if (!function_exists('imagecreatefromwebp')) {
[302] Fix | Delete
return $originalImageUrl;
[303] Fix | Delete
}
[304] Fix | Delete
$extension = 'webp';
[305] Fix | Delete
break;
[306] Fix | Delete
}
[307] Fix | Delete
if (!$extension) {
[308] Fix | Delete
return $originalImageUrl;
[309] Fix | Delete
}
[310] Fix | Delete
[311] Fix | Delete
return ResourceTranslator::urlToResource(Filesystem::pathToAbsoluteURL($cache->makeCache($extension, array(
[312] Fix | Delete
self::class,
[313] Fix | Delete
'_scaleImage'
[314] Fix | Delete
), array(
[315] Fix | Delete
$extension,
[316] Fix | Delete
$imagePath,
[317] Fix | Delete
$scale,
[318] Fix | Delete
$quality
[319] Fix | Delete
))));
[320] Fix | Delete
}
[321] Fix | Delete
}
[322] Fix | Delete
[323] Fix | Delete
public static function _scaleRemoteImage($targetFile, $extension, $imageUrl, $scale, $quality) {
[324] Fix | Delete
return self::_scaleImage($targetFile, $extension, $imageUrl, $scale, $quality);
[325] Fix | Delete
}
[326] Fix | Delete
[327] Fix | Delete
public static function _scaleImage($targetFile, $extension, $imagePath, $scale, $quality = 100) {
[328] Fix | Delete
$targetDir = dirname($targetFile);
[329] Fix | Delete
[330] Fix | Delete
$image = false;
[331] Fix | Delete
[332] Fix | Delete
if ($extension == 'png') {
[333] Fix | Delete
$image = @imagecreatefrompng($imagePath);
[334] Fix | Delete
} else if ($extension == 'jpg') {
[335] Fix | Delete
$image = @imagecreatefromjpeg($imagePath);
[336] Fix | Delete
if (function_exists("exif_read_data")) {
[337] Fix | Delete
$exif = @exif_read_data($imagePath);
[338] Fix | Delete
[339] Fix | Delete
$rotated = self::getOrientation($exif, $image);
[340] Fix | Delete
if ($rotated) {
[341] Fix | Delete
imagedestroy($image);
[342] Fix | Delete
$image = $rotated;
[343] Fix | Delete
}
[344] Fix | Delete
}
[345] Fix | Delete
} else if ($extension == 'webp') {
[346] Fix | Delete
//@TODO: should we need to care about rotation?
[347] Fix | Delete
$image = @imagecreatefromwebp($imagePath);
[348] Fix | Delete
}
[349] Fix | Delete
[350] Fix | Delete
if ($image) {
[351] Fix | Delete
$originalWidth = imagesx($image);
[352] Fix | Delete
$originalHeight = imagesy($image);
[353] Fix | Delete
$targetWidth = $originalWidth * $scale;
[354] Fix | Delete
$targetHeight = $originalHeight * $scale;
[355] Fix | Delete
if ((isset($rotated) && $rotated) || $originalWidth != $targetWidth || $originalHeight != $targetHeight) {
[356] Fix | Delete
$newImage = imagecreatetruecolor($targetWidth, $targetHeight);
[357] Fix | Delete
if ($extension == 'png' || $extension == 'webp') {
[358] Fix | Delete
imagesavealpha($newImage, true);
[359] Fix | Delete
imagealphablending($newImage, false);
[360] Fix | Delete
$transparent = imagecolorallocatealpha($newImage, 255, 255, 255, 127);
[361] Fix | Delete
imagefilledrectangle($image, 0, 0, $targetWidth, $targetHeight, $transparent);
[362] Fix | Delete
}
[363] Fix | Delete
[364] Fix | Delete
list($dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h) = self::imageMode($targetWidth, $targetHeight, $originalWidth, $originalHeight);
[365] Fix | Delete
imagecopyresampled($newImage, $image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
[366] Fix | Delete
imagedestroy($image);
[367] Fix | Delete
[368] Fix | Delete
} else {
[369] Fix | Delete
$newImage = $image;
[370] Fix | Delete
}
[371] Fix | Delete
[372] Fix | Delete
if (!Filesystem::existsFolder($targetDir)) {
[373] Fix | Delete
Filesystem::createFolder($targetDir);
[374] Fix | Delete
}
[375] Fix | Delete
if ($extension == 'png') {
[376] Fix | Delete
imagepng($newImage, $targetFile);
[377] Fix | Delete
} else if ($extension == 'jpg') {
[378] Fix | Delete
imagejpeg($newImage, $targetFile, $quality);
[379] Fix | Delete
} else if ($extension == 'webp') {
[380] Fix | Delete
imagewebp($newImage, $targetFile, $quality);
[381] Fix | Delete
}
[382] Fix | Delete
imagedestroy($newImage);
[383] Fix | Delete
[384] Fix | Delete
return true;
[385] Fix | Delete
}
[386] Fix | Delete
[387] Fix | Delete
throw new Exception('Unable to scale image: ' . $imagePath);
[388] Fix | Delete
}
[389] Fix | Delete
[390] Fix | Delete
private static function getOrientation($exif, $image) {
[391] Fix | Delete
if ($exif && !empty($exif['Orientation'])) {
[392] Fix | Delete
$rotated = false;
[393] Fix | Delete
switch ($exif['Orientation']) {
[394] Fix | Delete
case 3:
[395] Fix | Delete
$rotated = imagerotate($image, 180, 0);
[396] Fix | Delete
break;
[397] Fix | Delete
[398] Fix | Delete
case 6:
[399] Fix | Delete
$rotated = imagerotate($image, -90, 0);
[400] Fix | Delete
break;
[401] Fix | Delete
[402] Fix | Delete
case 8:
[403] Fix | Delete
$rotated = imagerotate($image, 90, 0);
[404] Fix | Delete
break;
[405] Fix | Delete
}
[406] Fix | Delete
[407] Fix | Delete
return $rotated;
[408] Fix | Delete
}
[409] Fix | Delete
[410] Fix | Delete
return false;
[411] Fix | Delete
}
[412] Fix | Delete
[413] Fix | Delete
private static function imageMode($width, $height, $originalWidth, $OriginalHeight, $mode = 'cover', $x = 50, $y = 50) {
[414] Fix | Delete
$dst_x = 0;
[415] Fix | Delete
$dst_y = 0;
[416] Fix | Delete
$src_x = 0;
[417] Fix | Delete
$src_y = 0;
[418] Fix | Delete
$dst_w = $width;
[419] Fix | Delete
$dst_h = $height;
[420] Fix | Delete
$src_w = $originalWidth;
[421] Fix | Delete
$src_h = $OriginalHeight;
[422] Fix | Delete
$horizontalRatio = $width / $originalWidth;
[423] Fix | Delete
$verticalRatio = $height / $OriginalHeight;
[424] Fix | Delete
[425] Fix | Delete
if ($horizontalRatio > $verticalRatio) {
[426] Fix | Delete
$new_h = round($horizontalRatio * $OriginalHeight);
[427] Fix | Delete
$dst_y = round(($height - $new_h) / 2 * $y / 50);
[428] Fix | Delete
$dst_h = $new_h;
[429] Fix | Delete
} else {
[430] Fix | Delete
$new_w = round($verticalRatio * $originalWidth);
[431] Fix | Delete
$dst_x = round(($width - $new_w) / 2 * $x / 50);
[432] Fix | Delete
$dst_w = $new_w;
[433] Fix | Delete
}
[434] Fix | Delete
[435] Fix | Delete
return array(
[436] Fix | Delete
$dst_x,
[437] Fix | Delete
$dst_y,
[438] Fix | Delete
$src_x,
[439] Fix | Delete
$src_y,
[440] Fix | Delete
$dst_w,
[441] Fix | Delete
$dst_h,
[442] Fix | Delete
$src_w,
[443] Fix | Delete
$src_h
[444] Fix | Delete
);
[445] Fix | Delete
}
[446] Fix | Delete
[447] Fix | Delete
private static function validateGDExtension($extension) {
[448] Fix | Delete
static $validExtensions = array(
[449] Fix | Delete
'png' => 'png',
[450] Fix | Delete
'jpg' => 'jpg',
[451] Fix | Delete
'jpeg' => 'jpg',
[452] Fix | Delete
'gif' => 'gif',
[453] Fix | Delete
'webp' => 'webp',
[454] Fix | Delete
'svg' => 'svg'
[455] Fix | Delete
);
[456] Fix | Delete
$extension = strtolower($extension);
[457] Fix | Delete
if (isset($validExtensions[$extension])) {
[458] Fix | Delete
return $validExtensions[$extension];
[459] Fix | Delete
}
[460] Fix | Delete
[461] Fix | Delete
return false;
[462] Fix | Delete
}
[463] Fix | Delete
[464] Fix | Delete
private static function validateExtension($extension) {
[465] Fix | Delete
static $validExtensions = array(
[466] Fix | Delete
'png' => 'png',
[467] Fix | Delete
'jpg' => 'jpg',
[468] Fix | Delete
'jpeg' => 'jpg',
[469] Fix | Delete
'gif' => 'gif',
[470] Fix | Delete
'webp' => 'webp',
[471] Fix | Delete
'svg' => 'svg'
[472] Fix | Delete
);
[473] Fix | Delete
$extension = strtolower($extension);
[474] Fix | Delete
if (isset($validExtensions[$extension])) {
[475] Fix | Delete
return $validExtensions[$extension];
[476] Fix | Delete
}
[477] Fix | Delete
[478] Fix | Delete
return false;
[479] Fix | Delete
}
[480] Fix | Delete
[481] Fix | Delete
public static function base64Transparent() {
[482] Fix | Delete
return 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7';
[483] Fix | Delete
}
[484] Fix | Delete
[485] Fix | Delete
public static function base64($imagePath, $image) {
[486] Fix | Delete
$pathInfo = pathinfo(parse_url($imagePath, PHP_URL_PATH));
[487] Fix | Delete
$extension = self::validateExtension($pathInfo['extension']);
[488] Fix | Delete
if ($extension) {
[489] Fix | Delete
return 'data:image/' . $extension . ';base64,' . Base64::encode(Filesystem::readFile($imagePath));
[490] Fix | Delete
}
[491] Fix | Delete
[492] Fix | Delete
return ResourceTranslator::toUrl($image);
[493] Fix | Delete
}
[494] Fix | Delete
[495] Fix | Delete
public static function exif_imagetype($filename) {
[496] Fix | Delete
if (!function_exists('exif_imagetype')) {
[497] Fix | Delete
if ((list($width, $height, $type, $attr) = getimagesize($filename)) !== false) {
[498] Fix | Delete
return $type;
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function