Last active
May 7, 2018 15:32
-
-
Save simbus82/3eb70128691ab93a6fd420ed6592e99f to your computer and use it in GitHub Desktop.
Codice per resize immagini Joomla con Jimage + salvataggio in cache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if (!is_dir(JPATH_SITE .'/cache/Qcache/')) { | |
mkdir(JPATH_SITE .'/cache/Qcache/', 0755, true); | |
} | |
$imgPath = JPATH_SITE . '/cache/Qcache/' . basename($immagineURL); | |
$imgURL = '/cache/Qcache/' . basename($immagineURL); | |
if (!file_exists($imgPath)) { | |
// Create our image object | |
$imageObj = new JImage(JPATH_SITE . $immagineURL); | |
$properties = JImage::getImageFileProperties(JPATH_SITE . $immagineURL); | |
//$properties = JImage::getImageFileProperties(JPATH_SITE . '/' . $immagineURL); //if not works | |
$mime = $properties->mime; | |
if ($mime == 'image/jpeg') | |
{ | |
$type = IMAGETYPE_JPEG; | |
} | |
elseif ($mime = 'image/png') | |
{ | |
$type = IMAGETYPE_PNG; | |
} | |
elseif ($mime = 'image/gif') | |
{ | |
$type = IMAGETYPE_GIF; | |
} | |
// Resize the image using the SCALE_INSIDE method | |
$imageObj = $imageObj->resize(300, 190, true, JImage::SCALE_INSIDE); | |
$imageObj->toFile($imgPath , $type); | |
$imageObj->destroy(); | |
} | |
echo '<img src="'.$imgURL.'"/>'; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment