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/SmartSli.../Slider/Feature
File: Optimize.php
<?php
[0] Fix | Delete
[1] Fix | Delete
[2] Fix | Delete
namespace Nextend\SmartSlider3\Slider\Feature;
[3] Fix | Delete
[4] Fix | Delete
[5] Fix | Delete
use Exception;
[6] Fix | Delete
use Nextend\Framework\FastImageSize\FastImageSize;
[7] Fix | Delete
use Nextend\Framework\Image\ImageEdit;
[8] Fix | Delete
use Nextend\Framework\ResourceTranslator\ResourceTranslator;
[9] Fix | Delete
[10] Fix | Delete
class Optimize {
[11] Fix | Delete
[12] Fix | Delete
private $slider;
[13] Fix | Delete
[14] Fix | Delete
private $playWhenVisible = 1;
[15] Fix | Delete
[16] Fix | Delete
private $playWhenVisibleAt = 0.5;
[17] Fix | Delete
[18] Fix | Delete
private $backgroundImageWidthNormal = 1920, $quality = 70, $thumbnailWidth = 100, $thumbnailHeight = 60, $thumbnailQuality = 70;
[19] Fix | Delete
[20] Fix | Delete
public function __construct($slider) {
[21] Fix | Delete
[22] Fix | Delete
$this->slider = $slider;
[23] Fix | Delete
[24] Fix | Delete
$this->playWhenVisible = intval($slider->params->get('playWhenVisible', 1));
[25] Fix | Delete
$this->playWhenVisibleAt = max(0, min(100, intval($slider->params->get('playWhenVisibleAt', 50)))) / 100;
[26] Fix | Delete
[27] Fix | Delete
$this->backgroundImageWidthNormal = intval($slider->params->get('optimize-slide-width-normal', 1920));
[28] Fix | Delete
$this->quality = intval($slider->params->get('optimize-quality', 70));
[29] Fix | Delete
[30] Fix | Delete
$this->thumbnailWidth = $slider->params->get('optimizeThumbnailWidth', 100);
[31] Fix | Delete
$this->thumbnailHeight = $slider->params->get('optimizeThumbnailHeight', 60);
[32] Fix | Delete
$this->thumbnailQuality = $slider->params->get('optimize-thumbnail-quality', 70);
[33] Fix | Delete
[34] Fix | Delete
[35] Fix | Delete
}
[36] Fix | Delete
[37] Fix | Delete
public function makeJavaScriptProperties(&$properties) {
[38] Fix | Delete
$properties['playWhenVisible'] = $this->playWhenVisible;
[39] Fix | Delete
$properties['playWhenVisibleAt'] = $this->playWhenVisibleAt;
[40] Fix | Delete
}
[41] Fix | Delete
[42] Fix | Delete
public function optimizeBackground($image, $x = 50, $y = 50) {
[43] Fix | Delete
try {
[44] Fix | Delete
$imageSize = FastImageSize::getSize($image);
[45] Fix | Delete
if ($imageSize) {
[46] Fix | Delete
$optimizeScale = $this->slider->params->get('optimize-scale', 0);
[47] Fix | Delete
[48] Fix | Delete
$targetWidth = $imageSize['width'];
[49] Fix | Delete
$targetHeight = $imageSize['height'];
[50] Fix | Delete
if ($optimizeScale && $targetWidth > $this->backgroundImageWidthNormal) {
[51] Fix | Delete
$targetHeight = ceil($this->backgroundImageWidthNormal / $targetWidth * $targetHeight);
[52] Fix | Delete
$targetWidth = $this->backgroundImageWidthNormal;
[53] Fix | Delete
}
[54] Fix | Delete
[55] Fix | Delete
return ImageEdit::resizeImage('slider/cache', ResourceTranslator::toPath($image), $targetWidth, $targetHeight, false, 'normal', 'ffffff', true, $this->quality, true, $x, $y);
[56] Fix | Delete
}
[57] Fix | Delete
[58] Fix | Delete
return $image;
[59] Fix | Delete
[60] Fix | Delete
} catch (Exception $e) {
[61] Fix | Delete
return $image;
[62] Fix | Delete
}
[63] Fix | Delete
}
[64] Fix | Delete
[65] Fix | Delete
public function optimizeThumbnail($image) {
[66] Fix | Delete
if ($this->slider->params->get('optimize-thumbnail-scale', 0)) {
[67] Fix | Delete
try {
[68] Fix | Delete
return ImageEdit::resizeImage('slider/cache', ResourceTranslator::toPath($image), $this->thumbnailWidth, $this->thumbnailHeight, false, 'normal', 'ffffff', true, $this->thumbnailQuality, true);
[69] Fix | Delete
} catch (Exception $e) {
[70] Fix | Delete
[71] Fix | Delete
return ResourceTranslator::toUrl($image);
[72] Fix | Delete
}
[73] Fix | Delete
}
[74] Fix | Delete
[75] Fix | Delete
return ResourceTranslator::toUrl($image);
[76] Fix | Delete
}
[77] Fix | Delete
[78] Fix | Delete
public function adminOptimizeThumbnail($image) {
[79] Fix | Delete
if ($this->slider->params->get('optimize-thumbnail-scale', 0)) {
[80] Fix | Delete
try {
[81] Fix | Delete
return ImageEdit::resizeImage('slider/cache', ResourceTranslator::toPath($image), $this->thumbnailWidth, $this->thumbnailHeight, true, 'normal', 'ffffff', true, $this->thumbnailQuality, true);
[82] Fix | Delete
} catch (Exception $e) {
[83] Fix | Delete
[84] Fix | Delete
return ResourceTranslator::toUrl($image);
[85] Fix | Delete
}
[86] Fix | Delete
}
[87] Fix | Delete
[88] Fix | Delete
return ResourceTranslator::toUrl($image);
[89] Fix | Delete
}
[90] Fix | Delete
[91] Fix | Delete
[92] Fix | Delete
public function optimizeImageWebP($src, $options) {
[93] Fix | Delete
[94] Fix | Delete
$options = array_merge(array(
[95] Fix | Delete
'optimize' => false,
[96] Fix | Delete
'quality' => 70,
[97] Fix | Delete
'resize' => false,
[98] Fix | Delete
'defaultWidth' => 1920,
[99] Fix | Delete
'mediumWidth' => 1200,
[100] Fix | Delete
'mediumHeight' => 0,
[101] Fix | Delete
'smallWidth' => 500,
[102] Fix | Delete
'smallHeight' => 0,
[103] Fix | Delete
'focusX' => 50,
[104] Fix | Delete
'focusY' => 50,
[105] Fix | Delete
'compressOriginal' => false
[106] Fix | Delete
), $options);
[107] Fix | Delete
}
[108] Fix | Delete
}
[109] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function