13 $sClass = trim($sClass,
'\\');
14 if (0 === strncmp(
'Intervention', $sClass, 12)) {
15 $sFile = CH_DIRECTORY_PATH_PLUGINS .
'intervention-image/' . str_replace(
'\\',
'/', $sClass) .
'.php';
20 spl_autoload_register(
'ch_intervention_image_autoload');
22 define(
'IMAGE_ERROR_SUCCESS', 0);
23 define(
'IMAGE_ERROR_WRONG_TYPE', 2);
25 if (!defined(
'CH_WSB_FILE_RIGHTS'))
26 define(
'CH_WSB_FILE_RIGHTS', 0666);
30 protected $w = 64,
$h = 64;
40 if (isset(
$GLOBALS[
'chWsbClasses'][get_class($this)]))
41 trigger_error (
'Multiple instances are not allowed for the class: ' . get_class($this), E_USER_ERROR);
43 $this->_isUseGD =
getParam(
'enable_gd') ==
'on' && extension_loaded(
'gd') ?
true :
false;
53 if (isset(
$GLOBALS[
'chWsbClasses'][get_class($this)]))
54 trigger_error(
'Clone is not allowed for the class: ' . get_class($this), E_USER_ERROR);
62 if(!isset(
$GLOBALS[
'chWsbClasses'][__CLASS__]))
65 return $GLOBALS[
'chWsbClasses'][__CLASS__];
81 $this->_oManager->make($sSrcImage);
83 catch (Exception $e) {
90 function resize ($mixedImage, $sDstImage =
'')
92 if (is_array($mixedImage)) {
94 foreach ($mixedImage
as $s) {
99 return $this->
_resize ($mixedImage, $sDstImage);
103 function applyWatermark ($mixedImage, $sDstImage, $sWtrImage, $iTransparency, $sPosition =
'bottom-right', $sPositionOffsetX = 0, $sPositionOffsetY = 0, $sScaleFactor = 0.2 )
105 if (is_array($mixedImage)) {
107 foreach ($mixedImage
as $s)
108 $aRet[] = $this->
_applyWatermark ($s,
$s, $sWtrImage, $iTransparency, $sPosition, $sPositionOffsetX, $sPositionOffsetY, $sScaleFactor);
111 return $this->
_applyWatermark ($mixedImage, $sDstImage, $sWtrImage, $iTransparency, $sPosition, $sPositionOffsetX, $sPositionOffsetY, $sScaleFactor);
117 if (is_array($mixedImage)) {
119 foreach ($mixedImage
as $s) {
124 return $this->
_grayscale ($mixedImage, $sDstImage);
136 $this->_isAutoCrop =
false;
144 $this->_isAutoCrop = $b;
154 $this->_iJpegQuality = $i;
159 $this->_isSquareResize = ($b ?
true :
false);
170 return $o->_getImageSize($sPath);
177 $o = $this->_oManager->make($sPath);
179 catch (Exception $e) {
180 $this->_sError = $e->getMessage();
183 return array (
'w' =>
$o->width(),
'h' =>
$o->height());
189 $sTmpFileName =
false;
192 if ($bCreateLocalFileIfUrl && preg_match(
'/^https?:\/\//', $sSrcImage)) {
193 $sTmpFileName = tempnam(CH_DIRECTORY_PATH_ROOT .
'tmp',
'');
194 file_put_contents($sTmpFileName, file_get_contents($sSrcImage));
198 $mixedRet = $this->_oManager
199 ->make($sTmpFileName ? $sTmpFileName : $sSrcImage)
202 catch (Exception $e) {
203 $this->_sError = $e->getMessage();
207 @unlink($sTmpFileName);
216 $a = $this->_oManager
219 ->pickColor(0, 0,
'array');
221 return array(
'r' => $a[0],
'g' => $a[1],
'b' => $a[2]);
223 catch (Exception $e) {
224 $this->_sError = $e->getMessage();
242 function crop($iScaledWidth, $iScaledHeight, $x, $y, $iCroppedWidth, $iCroppedHeight, $iRotation, $sSrcImage, $sDstImage =
'')
244 $iScaledWidth = round($iScaledWidth);
245 $iScaledHeight = round($iScaledHeight);
248 $o = $this->_oManager
250 ->resize($iScaledWidth, $iScaledHeight)
251 ->rotate($iRotation);
253 $iImgRotWidth =
$o->width();
254 $iImgRotHeight =
$o->height();
255 $dx = round(($iImgRotWidth - $iScaledWidth) / 2);
256 $dy = round(($iImgRotHeight - $iScaledHeight) / 2);
258 $o->crop($iScaledWidth, $iScaledHeight, $dx, $dy)
259 ->crop(round($iCroppedWidth), round($iCroppedHeight), $x, $y)
260 ->save($sDstImage ? $sDstImage : $sSrcImage, $this->_iJpegQuality);
262 catch (Exception $e) {
263 $this->_sError = $e->getMessage();
279 ->save($sDstImage ? $sDstImage : $sSrcImage, $this->_iJpegQuality);
281 chmod($sDstImage ? $sDstImage : $sSrcImage, CH_WSB_FILE_RIGHTS);
283 catch (Exception $e) {
284 $this->_sError = $e->getMessage();
291 function _resize ($sSrcImage, $sDstImage =
'')
295 if ($this->_isAutoCrop || $this->_isSquareResize) {
299 ->fit($this->w, $this->_isSquareResize ? $this->w : $this->h,
null,
'top')
300 ->save($sDstImage ? $sDstImage : $sSrcImage, $this->_iJpegQuality);
306 ->resize($this->w, $this->h,
function ($constraint) {
307 $constraint->aspectRatio();
308 $constraint->upsize();
310 ->
save($sDstImage ? $sDstImage : $sSrcImage, $this->_iJpegQuality);
312 chmod($sDstImage ? $sDstImage : $sSrcImage, CH_WSB_FILE_RIGHTS);
314 catch (Exception $e) {
315 $this->_sError = $e->getMessage();
322 function _applyWatermark( $sSrcImage, $sDstImage, $sWtrImage, $iTransparency, $sPosition =
'bottom-right', $sPositionOffsetX = 0, $sPositionOffsetY = 0, $sScaleFactor = 0.2)
326 $oImageOrig = $this->_oManager->make($sSrcImage);
329 ->insert($this->_oManager
331 ->
resize(round($oImageOrig->width() * $sScaleFactor), round($oImageOrig->height() * $sScaleFactor), function ($constraint) {
332 $constraint->aspectRatio();
333 $constraint->upsize();
335 ->opacity($iTransparency),
336 $sPosition, $sPositionOffsetX, $sPositionOffsetY)
337 ->save($sDstImage ? $sDstImage : $sSrcImage, $this->_iJpegQuality);
339 chmod($sDstImage ? $sDstImage : $sSrcImage, CH_WSB_FILE_RIGHTS);
341 catch (Exception $e) {
342 $this->_sError = $e->getMessage();