Skip to content

Instantly share code, notes, and snippets.

@simbus82
Last active May 7, 2018 15:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simbus82/3eb70128691ab93a6fd420ed6592e99f to your computer and use it in GitHub Desktop.
Save simbus82/3eb70128691ab93a6fd420ed6592e99f to your computer and use it in GitHub Desktop.
Codice per resize immagini Joomla con Jimage + salvataggio in cache
<?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