salve, lo script di seguito crea un'anteprima (thumb) dell'immagine basandosi su dei valori maxheight e maxwidth.
esempio:150x150px
lo script ridimensiona a 150px mantenendo l'aspect ratio (così una dimensione è 150px e l'altra è minore)
penso di aver individuato la funzione che crea effettivamente l'immagine
codice:function resizeImageGD2($src_file, $dest_file, $destWidth,$destHeight){ $imginfo = getimagesize($src_file); if ($imginfo == null) { $this->raiseError(CBTxt::T('Error: Unable to execute getimagesize function')); return false; } // GD can only handle JPG & PNG images if ($imginfo[2] != 2 && $imginfo[2] != 3 && ($imginfo[2] == 1 && !function_exists( 'imagecreatefromgif' ))){ $this->raiseError(CBTxt::T('Error: GD2 Unable to create image from imagetype function')); return false; } if ($imginfo[2] == 2) $src_img = imagecreatefromjpeg($src_file); elseif ($imginfo[2] == 1) $src_img = imagecreatefromgif($src_file); else $src_img = imagecreatefrompng($src_file); if (!$src_img) { $this->raiseError(CBTxt::T('Error: GD2 Unable to create image from imagetype function')); return false; } $dst_img = imagecreatetruecolor($destWidth, $destHeight); $background_color = imagecolorallocate( $dst_img, 255, 255, 255 ); // white background for images with transparency ImageFilledRectangle($dst_img, 0, 0, $destWidth, $destHeight, $background_color); imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $destWidth, $destHeight, $imginfo[0], $imginfo[1]); if ($imginfo[2] == 2) { imagejpeg($dst_img, $dest_file, $this->_JPEGquality); } elseif ($imginfo[2] == 1) { if(function_exists('imagegif')) { imagegif($dst_img, $dest_file); } else { $this->raiseError(CBTxt::T('Error: GIF Uploads are not supported by this version of GD')); return false; } } else { imagepng($dst_img, $dest_file); } imagedestroy($src_img); imagedestroy($dst_img); return true; }
questo è lo script completo
http://forge.joomlapolis.com/attachm...lbox.class.php
appartiene a Community Builder, un componente di joomla.
quello che vorrei è:
avere una thumb che abbia dimensioni fisse 150x150 (non variabili 150xX o Xx150) croppando l'immagine.
in altre parole, per capirci, come gli avatar di facebook.
so che è una richiesta impegnativa, ma non così tanto per chi sviluppa ed ha a che fare spesso con l'image processing.

Rispondi quotando
