Resizing a image with PHP and GD2. I'm getting the image and a black background

AFeSteve

New Member
I'm creating a dynamic class to generate various images.ImagesUtils.php\[code\]<?phpclass ImagesUtils{ private $nombre_imagen = null; private $imagen = null; private $extension = null; private $directorio = null; private $width = null; private $height = null; private $tipo = null; private $final_width = null; private $final_height = null; private $nuevo_nombre = null; private $nuevo_directorio = null; public function __construct($imagen, $directorio = '') { $this->directorio = realpath("..".DS."data".DS."storage".DS."files".DS.$directorio); $this->imagen = $this->directorio.DS.$imagen; $this->nombre_imagen = $imagen; $this->extension = substr($imagen, strrpos($imagen, '.') + 1, strlen($imagen)); $propiedades = getimagesize($this->imagen); $this->width = $propiedades["0"]; $this->height = $propiedades["1"]; $this->tipo = $propiedades["2"]; } public function Resize($width = null, $height = null, $proporcion = true) { $this->final_width = $width; $this->final_height = $height; if(true == $proporcion) self::proporcion($width, $height); $imagen = imagecreatefromjpeg($this->imagen); $nueva_imagen = imagecreatetruecolor($this->final_width, $this->final_height); imagecopyresampled($nueva_imagen, $imagen, 0, 0, 0, 0, $this->final_width, $this->final_height, $this->width, $this->height); return imagejpeg($image, $this->nueva_imagen); }}?>\[/code\]And how I call:\[code\]$procesar_imagen = new ImagesUtils($imagen["nombre"]);$procesar_imagen->Resize(640, 480);\[/code\]Width this code works fine... but if I use this:\[code\]$procesar_imagen->Resize(300, 300);\[/code\]My final image generated looks like: http://i51.tinypic.com/htwx79.jpgThe input image is: http://i51.tinypic.com/15n9ifc.jpgI don't know how to solve it... my proporcion() fuction returns the new height and width from the aspect ratio of the photo... i checked and the values are right, the width returned is 300 (and the final image width is 300... but counting the black area).Thanks in advance!
 
Back
Top