Author Topic: VM 2.0.20b thumbnails crop  (Read 1930 times)

shnubis

  • Beginner
  • *
  • Posts: 2
  • Skype Name: trixter5
VM 2.0.20b thumbnails crop
« on: April 03, 2013, 14:02:44 pm »
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?

anisimow

  • Beginner
  • *
  • Posts: 21
  • Skype Name: anisimowsjava
Re: VM 2.0.20b thumbnails crop
« Reply #1 on: November 02, 2013, 02:11:22 am »
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
Code: [Select]
if ($orig_size[0]<$orig_size[1])to
Code: [Select]
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.

Maxim Pishnyak

  • Global Moderator
  • Sr. Member
  • *
  • Posts: 2664
Re: VM 2.0.20b thumbnails crop
« Reply #2 on: November 22, 2013, 18:36:54 pm »
Yes, please, share.
You can support Community by voting for Project on the JED
https://extensions.joomla.org/extension/virtuemart/#reviews
Join us at
https://twitter.com/virtuemart

anisimow

  • Beginner
  • *
  • Posts: 21
  • Skype Name: anisimowsjava
Re: VM 2.0.20b thumbnails crop
« Reply #3 on: November 23, 2013, 08:08:05 am »
Yes, please, share.
I dont remember where is it, but here my full code for crop, I hope it helps for you
Code: [Select]
*
* 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;
}

Maxim Pishnyak

  • Global Moderator
  • Sr. Member
  • *
  • Posts: 2664
Re: VM 2.0.20b thumbnails crop
« Reply #4 on: November 23, 2013, 13:09:50 pm »
Nice, thank you for sharing your experience.
You can support Community by voting for Project on the JED
https://extensions.joomla.org/extension/virtuemart/#reviews
Join us at
https://twitter.com/virtuemart