Hi,
how i can CROP thumbnails not resize product and category images?
VM can only resize images :(
Using VM 2.0.20b and Joomla! 2.5.9
Cant find any solution 4 this.
Can anyone help?
Good Day. I now solution to resize image that way it's newer overflow your dimension.
in /administrator/components/com_virtuemart/helpers/Img2Thumb.php in NewImgResize function you must change condition at line 209
if ($orig_size[0]<$orig_size[1])
to
if (($orig_size[0]/$orig_size[1])<($maxX/$maxY))
I also have solution for crop image, but its not properly tested, and code does not optimized, but it like works. If you want I can give you.
Yes, please, share.
Quote from: Maxim Pishnyak on November 22, 2013, 18:36:54 PM
Yes, please, share.
I dont remember where is it, but here my full code for crop, I hope it helps for you
*
* private function - do not call
* includes function ImageCreateTrueColor and ImageCopyResampled which are available only under GD 2.0.1 or higher !
*/
private function NewImgResize($orig_img,$newxsize,$newysize,$filename)
{
//getimagesize returns array
// [0] = width in pixels
// [1] = height in pixels
// [2] = type
// [3] = img tag "width=xx height=xx" values
$orig_size = getimagesize($filename);
$maxX = $newxsize;
$maxY = $newysize;
if ($orig_size[0]<$orig_size[1])
{
$newxsize = $newysize * ($orig_size[0]/$orig_size[1]);
$adjustX = ($maxX - $newxsize)/2;
$adjustY = 0;
}
else
{
$newysize = $newxsize / ($orig_size[0]/$orig_size[1]);
$adjustX = 0;
$adjustY = ($maxY - $newysize)/2;
}
/* Original code removed to allow for maxSize thumbnails
$im_out = ImageCreateTrueColor($newxsize,$newysize);
ImageCopyResampled($im_out, $orig_img, 0, 0, 0, 0,
$newxsize, $newysize,$orig_size[0], $orig_size[1]);
*/
// New modification - creates new image at maxSize
if( $this->maxSize )
{
if( function_exists("imagecreatetruecolor") )
$im_out = imagecreatetruecolor($maxX,$maxY);
else
$im_out = imagecreate($maxX,$maxY);
// Need to image fill just in case image is transparent, don't always want black background
$bgfill = imagecolorallocate( $im_out, $this->bg_red, $this->bg_green, $this->bg_blue );
if( function_exists( "imageAntiAlias" )) {
imageAntiAlias($im_out,true);
}
imagealphablending($im_out, false);
if( function_exists( "imagesavealpha")) {
imagesavealpha($im_out,true);
}
if( function_exists( "imagecolorallocatealpha")) {
$transparent = imagecolorallocatealpha($im_out, 255, 255, 255, 127);
}
//imagefill( $im_out, 0,0, $bgfill );
if( function_exists("imagecopyresampled") ){
ImageCopyResampled($im_out, $orig_img, $adjustX, $adjustY, 0, 0, $newxsize, $newysize,$orig_size[0], $orig_size[1]);
}
else {
ImageCopyResized($im_out, $orig_img, $adjustX, $adjustY, 0, 0, $newxsize, $newysize,$orig_size[0], $orig_size[1]);
}
}
else
{
$w = $orig_size[0];
$h = $orig_size[1];
if(!($w < $maxX or $h < $maxY)) {;
$ratio = max($maxX/$w, $maxY/$h);
$h = $maxY / $ratio;
$x = ($w - $maxX / $ratio) / 2;
$w = $maxX / $ratio;
$newxsize = $maxX;
$newysize = $maxY;
}
if( function_exists("imagecreatetruecolor") )
$im_out = ImageCreateTrueColor($newxsize,$newysize);
else
$im_out = imagecreate($newxsize,$newysize);
if( function_exists( "imageAntiAlias" ))
imageAntiAlias($im_out,true);
imagealphablending($im_out, false);
if( function_exists( "imagesavealpha"))
imagesavealpha($im_out,true);
if( function_exists( "imagecolorallocatealpha"))
$transparent = imagecolorallocatealpha($im_out, 255, 255, 255, 127);
if( function_exists("imagecopyresampled") ){
if($w < $maxX or $h < $maxY){
ImageCopyResampled($im_out, $orig_img, 0, 0, 0, 0, $newxsize, $newysize,$orig_size[0], $orig_size[1]);
}else{
Imagecopyresampled($im_out, $orig_img, 0, 0, $x, 0, $maxX, $maxY, $w, $h);
}
}
else
if($w < $maxX or $h < $maxY){
ImageCopyResized($im_out, $orig_img, 0, 0, 0, 0, $newxsize, $newysize,$orig_size[0], $orig_size[1]);
}else{
ImageCopyResized($im_out, $orig_img, 0, 0, $x, 0, $maxX, $maxY, $w, $h);
}
}
return $im_out;
}
Nice, thank you for sharing your experience.