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.../FastImag...
File: FastImageSize.php
<?php
[0] Fix | Delete
[1] Fix | Delete
/**
[2] Fix | Delete
* fast-image-size base class
[3] Fix | Delete
*
[4] Fix | Delete
* @package fast-image-size
[5] Fix | Delete
* @copyright (c) Marc Alexander <admin@m-a-styles.de>
[6] Fix | Delete
*
[7] Fix | Delete
* For the full copyright and license information, please view the LICENSE
[8] Fix | Delete
* file that was distributed with this source code.
[9] Fix | Delete
*/
[10] Fix | Delete
[11] Fix | Delete
namespace Nextend\Framework\FastImageSize;
[12] Fix | Delete
[13] Fix | Delete
use Nextend\Framework\Pattern\SingletonTrait;
[14] Fix | Delete
use Nextend\Framework\ResourceTranslator\ResourceTranslator;
[15] Fix | Delete
[16] Fix | Delete
class FastImageSize {
[17] Fix | Delete
[18] Fix | Delete
use SingletonTrait;
[19] Fix | Delete
[20] Fix | Delete
private static $cache = array();
[21] Fix | Delete
[22] Fix | Delete
/**
[23] Fix | Delete
* @param string $image
[24] Fix | Delete
* @param array $attributes
[25] Fix | Delete
*/
[26] Fix | Delete
public static function initAttributes($image, &$attributes) {
[27] Fix | Delete
[28] Fix | Delete
$size = self::getSize($image);
[29] Fix | Delete
[30] Fix | Delete
if ($size) {
[31] Fix | Delete
$attributes['width'] = $size['width'];
[32] Fix | Delete
$attributes['height'] = $size['height'];
[33] Fix | Delete
}
[34] Fix | Delete
}
[35] Fix | Delete
[36] Fix | Delete
public static function getWidth($image) {
[37] Fix | Delete
[38] Fix | Delete
$size = self::getSize($image);
[39] Fix | Delete
[40] Fix | Delete
if ($size) {
[41] Fix | Delete
return $size['width'];
[42] Fix | Delete
}
[43] Fix | Delete
[44] Fix | Delete
return 0;
[45] Fix | Delete
}
[46] Fix | Delete
[47] Fix | Delete
public static function getSize($image) {
[48] Fix | Delete
$imagePath = ResourceTranslator::toPath($image);
[49] Fix | Delete
[50] Fix | Delete
if (!isset(self::$cache[$imagePath])) {
[51] Fix | Delete
if (empty($imagePath)) {
[52] Fix | Delete
self::$cache[$imagePath] = false;
[53] Fix | Delete
} else {
[54] Fix | Delete
self::$cache[$imagePath] = self::getInstance()
[55] Fix | Delete
->getImageSize($imagePath);
[56] Fix | Delete
}
[57] Fix | Delete
}
[58] Fix | Delete
[59] Fix | Delete
return self::$cache[$imagePath];
[60] Fix | Delete
}
[61] Fix | Delete
[62] Fix | Delete
/** @var array Size info that is returned */
[63] Fix | Delete
protected $size = array();
[64] Fix | Delete
[65] Fix | Delete
/** @var string Data retrieved from remote */
[66] Fix | Delete
protected $data = '';
[67] Fix | Delete
[68] Fix | Delete
/** @var array List of supported image types and associated image types */
[69] Fix | Delete
protected $supportedTypes = array(
[70] Fix | Delete
'png' => array('png'),
[71] Fix | Delete
'gif' => array('gif'),
[72] Fix | Delete
'jpeg' => array(
[73] Fix | Delete
'jpeg',
[74] Fix | Delete
'jpg'
[75] Fix | Delete
),
[76] Fix | Delete
'webp' => array(
[77] Fix | Delete
'webp',
[78] Fix | Delete
),
[79] Fix | Delete
'svg' => array(
[80] Fix | Delete
'svg',
[81] Fix | Delete
)
[82] Fix | Delete
);
[83] Fix | Delete
[84] Fix | Delete
/** @var array Class map that links image extensions/mime types to class */
[85] Fix | Delete
protected $classMap;
[86] Fix | Delete
[87] Fix | Delete
/** @var array An array containing the classes of supported image types */
[88] Fix | Delete
protected $type;
[89] Fix | Delete
[90] Fix | Delete
/**
[91] Fix | Delete
* Get image dimensions of supplied image
[92] Fix | Delete
*
[93] Fix | Delete
* @param string $file Path to image that should be checked
[94] Fix | Delete
* @param string $type Mimetype of image
[95] Fix | Delete
*
[96] Fix | Delete
* @return array|bool Array with image dimensions if successful, false if not
[97] Fix | Delete
*/
[98] Fix | Delete
public function getImageSize($file, $type = '') {
[99] Fix | Delete
// Reset values
[100] Fix | Delete
$this->resetValues();
[101] Fix | Delete
[102] Fix | Delete
// Treat image type as unknown if extension or mime type is unknown
[103] Fix | Delete
if (!preg_match('/\.([a-z0-9]+)$/i', $file, $match) && empty($type)) {
[104] Fix | Delete
$this->getImagesizeUnknownType($file);
[105] Fix | Delete
} else {
[106] Fix | Delete
$extension = (empty($type) && isset($match[1])) ? $match[1] : preg_replace('/.+\/([a-z0-9-.]+)$/i', '$1', $type);
[107] Fix | Delete
[108] Fix | Delete
$this->getImageSizeByExtension($file, $extension);
[109] Fix | Delete
}
[110] Fix | Delete
[111] Fix | Delete
return sizeof($this->size) > 1 ? $this->size : false;
[112] Fix | Delete
}
[113] Fix | Delete
[114] Fix | Delete
/**
[115] Fix | Delete
* Get dimensions of image if type is unknown
[116] Fix | Delete
*
[117] Fix | Delete
* @param string $filename Path to file
[118] Fix | Delete
*/
[119] Fix | Delete
protected function getImagesizeUnknownType($filename) {
[120] Fix | Delete
// Grab the maximum amount of bytes we might need
[121] Fix | Delete
$data = $this->getImage($filename, 0, Type\TypeJpeg::JPEG_MAX_HEADER_SIZE, false);
[122] Fix | Delete
[123] Fix | Delete
if ($data !== false) {
[124] Fix | Delete
$this->loadAllTypes();
[125] Fix | Delete
foreach ($this->type as $imageType) {
[126] Fix | Delete
$imageType->getSize($filename);
[127] Fix | Delete
[128] Fix | Delete
if (sizeof($this->size) > 1) {
[129] Fix | Delete
break;
[130] Fix | Delete
}
[131] Fix | Delete
}
[132] Fix | Delete
}
[133] Fix | Delete
}
[134] Fix | Delete
[135] Fix | Delete
/**
[136] Fix | Delete
* Get image size by file extension
[137] Fix | Delete
*
[138] Fix | Delete
* @param string $file Path to image that should be checked
[139] Fix | Delete
* @param string $extension Extension/type of image
[140] Fix | Delete
*/
[141] Fix | Delete
protected function getImageSizeByExtension($file, $extension) {
[142] Fix | Delete
$extension = strtolower($extension);
[143] Fix | Delete
$this->loadExtension($extension);
[144] Fix | Delete
if (isset($this->classMap[$extension])) {
[145] Fix | Delete
$this->classMap[$extension]->getSize($file);
[146] Fix | Delete
}
[147] Fix | Delete
}
[148] Fix | Delete
[149] Fix | Delete
/**
[150] Fix | Delete
* Reset values to default
[151] Fix | Delete
*/
[152] Fix | Delete
protected function resetValues() {
[153] Fix | Delete
$this->size = array();
[154] Fix | Delete
$this->data = '';
[155] Fix | Delete
}
[156] Fix | Delete
[157] Fix | Delete
/**
[158] Fix | Delete
* Set mime type based on supplied image
[159] Fix | Delete
*
[160] Fix | Delete
* @param int $type Type of image
[161] Fix | Delete
*/
[162] Fix | Delete
public function setImageType($type) {
[163] Fix | Delete
$this->size['type'] = $type;
[164] Fix | Delete
}
[165] Fix | Delete
[166] Fix | Delete
/**
[167] Fix | Delete
* Set size info
[168] Fix | Delete
*
[169] Fix | Delete
* @param array $size Array containing size info for image
[170] Fix | Delete
*/
[171] Fix | Delete
public function setSize($size) {
[172] Fix | Delete
$this->size = $size;
[173] Fix | Delete
}
[174] Fix | Delete
[175] Fix | Delete
/**
[176] Fix | Delete
* Get image from specified path/source
[177] Fix | Delete
*
[178] Fix | Delete
* @param string $filename Path to image
[179] Fix | Delete
* @param int $offset Offset at which reading of the image should start
[180] Fix | Delete
* @param int $length Maximum length that should be read
[181] Fix | Delete
* @param bool $forceLength True if the length needs to be the specified
[182] Fix | Delete
* length, false if not. Default: true
[183] Fix | Delete
*
[184] Fix | Delete
* @return false|string Image data or false if result was empty
[185] Fix | Delete
*/
[186] Fix | Delete
public function getImage($filename, $offset, $length, $forceLength = true) {
[187] Fix | Delete
if (empty($this->data)) {
[188] Fix | Delete
$this->data = @file_get_contents($filename, false, null, $offset, $length);
[189] Fix | Delete
}
[190] Fix | Delete
[191] Fix | Delete
// Force length to expected one. Return false if data length
[192] Fix | Delete
// is smaller than expected length
[193] Fix | Delete
if ($forceLength === true) {
[194] Fix | Delete
return (strlen($this->data) < $length) ? false : substr($this->data, $offset, $length);
[195] Fix | Delete
}
[196] Fix | Delete
[197] Fix | Delete
return empty($this->data) ? false : $this->data;
[198] Fix | Delete
}
[199] Fix | Delete
[200] Fix | Delete
/**
[201] Fix | Delete
* Get return data
[202] Fix | Delete
*
[203] Fix | Delete
* @return array|bool Size array if dimensions could be found, false if not
[204] Fix | Delete
*/
[205] Fix | Delete
protected function getReturnData() {
[206] Fix | Delete
return sizeof($this->size) > 1 ? $this->size : false;
[207] Fix | Delete
}
[208] Fix | Delete
[209] Fix | Delete
/**
[210] Fix | Delete
* Load all supported types
[211] Fix | Delete
*/
[212] Fix | Delete
protected function loadAllTypes() {
[213] Fix | Delete
foreach ($this->supportedTypes as $imageType => $extension) {
[214] Fix | Delete
$this->loadType($imageType);
[215] Fix | Delete
}
[216] Fix | Delete
}
[217] Fix | Delete
[218] Fix | Delete
/**
[219] Fix | Delete
* Load an image type by extension
[220] Fix | Delete
*
[221] Fix | Delete
* @param string $extension Extension of image
[222] Fix | Delete
*/
[223] Fix | Delete
protected function loadExtension($extension) {
[224] Fix | Delete
if (isset($this->classMap[$extension])) {
[225] Fix | Delete
return;
[226] Fix | Delete
}
[227] Fix | Delete
foreach ($this->supportedTypes as $imageType => $extensions) {
[228] Fix | Delete
if (in_array($extension, $extensions, true)) {
[229] Fix | Delete
$this->loadType($imageType);
[230] Fix | Delete
}
[231] Fix | Delete
}
[232] Fix | Delete
}
[233] Fix | Delete
[234] Fix | Delete
/**
[235] Fix | Delete
* Load an image type
[236] Fix | Delete
*
[237] Fix | Delete
* @param string $imageType Mimetype
[238] Fix | Delete
*/
[239] Fix | Delete
protected function loadType($imageType) {
[240] Fix | Delete
if (isset($this->type[$imageType])) {
[241] Fix | Delete
return;
[242] Fix | Delete
}
[243] Fix | Delete
[244] Fix | Delete
$className = '\\' . __NAMESPACE__ . '\Type\Type' . ucfirst($imageType);
[245] Fix | Delete
[246] Fix | Delete
$this->type[$imageType] = new $className($this);
[247] Fix | Delete
[248] Fix | Delete
// Create class map
[249] Fix | Delete
foreach ($this->supportedTypes[$imageType] as $ext) {
[250] Fix | Delete
/** @var Type\TypeInterface */
[251] Fix | Delete
$this->classMap[$ext] = $this->type[$imageType];
[252] Fix | Delete
}
[253] Fix | Delete
}
[254] Fix | Delete
}
[255] Fix | Delete
[256] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function