News:

Support the VirtueMart project and become a member

Main Menu

[Bug] VM2 Enable Dynamic Thumbnail Resizing

Started by bunak, July 14, 2012, 19:56:18 PM

Previous topic - Next topic

bunak

Hi all
We have find some bug with Enable Dynamic Thumbnail Resizing

If image have wrong extanshion in name, for eaxample 111.jpg for png - image, then VM don't correct resized it. VM resize 111.jpg to 111_150_150.jpg.png but in virtuemart_media table set file_url_thumb = 111_150_150.jpg
So real file in resized folder is 111_150_150.jpg.png but in file_url_thumb = 111_150_150.jpg
In this casethumb image don't show

bunak

#1
We solved this problem by this huks, loock for "-----------------------------------------<<<" comment:

In administrator\components\com_virtuemart\helpers\img2thumb.php

1. add var $type; in class
class Img2Thumb {
// New modification
/**
* private variables - do not use
*
* @var int $bg_red 0-255 - red color variable for background filler
* @var int $bg_green 0-255 - green color variable for background filler
* @var int $bg_blue 0-255 - blue color variable for background filler
* @var int $maxSize 0-1 - true/false - should thumbnail be filled to max pixels
*/
var $bg_red;
var $bg_green;
var $bg_blue;
var $maxSize;
/**
* @var string Filename for the thumbnail
*/
var $fileout;
var $type; // bunak, shemetok - type of creted file -----------------------------------------<<<


2. save real type of thumb file into new var $type in class Img2Thumb->NewImgCreate function
private function NewImgCreate($filename,$newxsize,$newysize,$fileout)
{
// if( !function_exists('imagecreatefromjpeg') ){
// $app = JFactory::getApplication();
// $app->enqueueMessage('This server does NOT suppport auto generating Thumbnails by jpg');
// }

$type = $this->GetImgType($filename);
$this->type = $type; // bunak, shemetok - type of creted file -----------------------------------------<<<


In \administrator\components\com_virtuemart\helpers\image.php

3. In createThumb check the real extanshion of type and add it to file path if needed
if (file_exists($fullSizeFilenamePath)) {
if (!class_exists('Img2Thumb')) require(JPATH_VM_ADMINISTRATOR.DS.'helpers'.DS.'img2thumb.php');
$createdImage = new Img2Thumb($fullSizeFilenamePath, $width, $height, $resizedFilenamePath, $maxsize, $bgred, $bggreen, $bgblue);

// bunak, shemetok - check type of creted file -----------------------------------------<<<
$file_added_extension = "";
if($createdImage->type != $this->file_extension) $file_added_extension = '.'.$createdImage->type;

if($createdImage){
return $this->file_url_folder_thumb.$this->file_name_thumb.'.'.$this->file_extension . $file_added_extension;
// bunak, shemetok - check type of creted file -----------------------------------------<<<
} else {
return 0;
}
} else {
vmError('Couldnt create thumb, file not found '.$fullSizeFilenamePath);
return 0;
}


[attachment cleanup by admin]