Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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