×
Kunena 5.1.5 Released - Security Release (14 Oct 2018)

The Kunena team has announce the arrival of Kunena 5.1.5 [K 5.1.5] which is now available for download as a native Joomla extension for J! 3.8.x. This version addresses most of the issues that were discovered in K 5.1 and issues discovered during the development stages of K 5.1. This is a Security release.

× Please note: The Kunena project team takes NO responsibility for maintaining nor supporting anything in this category.

Loved Error 500 - Internal server error when uploading and resizing images - my solution using IMAGICK

More
4 years 10 months ago #1 by WolfgangOWL
When users at our forum uploaded oversized imagages they got an error 500. I looked into the matter and found out that GD is eating up too much memory. I tried out IMAGICK and this is working fine without producing errors. So I modified kunena.upload.class.php and following is the code I use now. Maybe someone with more experience than me can modify it so that all allowed image formats will be processed by IMAGICK. I would be gratetful if in future versions of Kunena IMAGICK would be supported.

// If image is not inside allowed size limits, resize it
if ($this->fileSize > $this->imagesize || $this->imageInfo->width > $this->imagewidth || $this->imageInfo->height > $this->imageheight)
{
// test if imagick is loaded and image is jpeg
if ( extension_loaded('imagick') && getimagesize($this->fileTemp)[2] == 2 )
{
$imageImagick = new Imagick($this->fileTemp);
$imageImagick->setImageCompression(Imagick::COMPRESSION_JPEG);
$imageImagick->setImageCompressionQuality($this->imagequality);
$imageImagick->resizeImage($this->imagewidth, $this->imageheight, imagick::FILTER_LANCZOS, 1.0, true);
$imageImagick->writeImage($this->fileTemp);
$imageImagick->destroy();
}
else
{
$options = array('quality' => $this->imagequality);
$imageRaw = new CKunenaImage($this->fileTemp);
if ($imageRaw->getError())
{
$this->fail(JText::_($imageRaw->getError()));
return false;
}
$image = $imageRaw->resize($this->imagewidth, $this->imageheight);
$type = $imageRaw->getType();
unset($imageRaw);
$image->toFile($this->fileTemp,$type,$options);
}
clearstatcache();
// Re-calculate physical file size: image has been shrunk
$stat = stat($this->fileTemp);
if (! $stat) {
$this->fail(JText::_('COM_KUNENA_UPLOAD_ERROR_STAT', $this->fileTemp));
return false;
}
$this->fileSize = $stat;
}

Please Log in or Create an account to join the conversation.

More
4 years 10 months ago #2 by WolfgangOWL
The construct

if ( extension_loaded('imagick') && getimagesize($this->fileTemp)[2] == 2 )
{
...
}

may not work with older PHP versions. To be safe use the following code instead:

$testImagick = getimagesize($this->fileTemp);
if ( extension_loaded('imagick') && $testImagick[2] == 2 )
{
...
}

Please Log in or Create an account to join the conversation.

  • Not Allowed: to create new topic.
  • Not Allowed: to reply.
  • Not Allowed: to add attachements.
  • Not Allowed: to edit your message.
Time to create page: 0.099 seconds