@abimaelrc,
no me funciona con tu script, me pone el fondo negro, te dejo mi como tengo mi clase para que vas:
Código PHP:
Ver original<?php
class SimpleImage {
private $image;
private $image_type;
private $instance;
private $transparent;
/**
* patron singleton
*
* @version 0.2
* @author Lucas M. Sastre
* @access Public
* @name singleton
*
* @return $instance
*
* Modificado:
*
*/
public static function singleton() {
if( self::$instance == null ) {
self::$instance = new self();
}
return self::$instance;
}
public function setTransparent($bool)
{
$this->transparent = (boolean)$bool;
}
/**
* carga una imagen para obtener su propiedades
*
* @version 0.2
* @author Lucas M. Sastre
* @access Public
* @name load
*
* @param string $filename
*
* Modificado:
*
*/
public function load($filename) {
$this->image_type = $image_info[2];
if( $this->image_type == IMAGETYPE_JPEG ) {
} elseif( $this->image_type == IMAGETYPE_GIF ) {
} elseif( $this->image_type == IMAGETYPE_PNG ) {
}
}
/**
* guarda una imagen
*
* @version 0.2
* @author Lucas M. Sastre
* @access Public
* @name save
*
* @param string $filename
* @param string $image_type
* @param integer $compression
* @param integer $permissions
*
* Modificado:
*
*/
public function save($filename, $image_type=IMAGETYPE_JPEG, $compression=75, $permissions=null) {
if( $image_type == IMAGETYPE_JPEG ) {
imagejpeg($this->image,$filename,$compression); } elseif( $image_type == IMAGETYPE_GIF ) {
} elseif( $image_type == IMAGETYPE_PNG ) {
}
if( $permissions != null) {
chmod($filename,$permissions); }
}
/**
* genera la salida de la image segun su extension
*
* @version 0.2
* @author Lucas M. Sastre
* @access Public
* @name output
*
* @param string $image_type
*
* Modificado:
*
*/
public function output($image_type=IMAGETYPE_JPEG) {
if( $image_type == IMAGETYPE_JPEG ) {
} elseif( $image_type == IMAGETYPE_GIF ) {
} elseif( $image_type == IMAGETYPE_PNG ) {
}
}
/**
* recupera el ancho de la imagen
*
* @version 0.2
* @author Lucas M. Sastre
* @access Public
* @name getWidth
*
* Modificado:
*
*/
public function getWidth() {
}
/**
* recupera el alto de la imagen
*
* @version 0.2
* @author Lucas M. Sastre
* @access Public
* @name getHeight
*
* Modificado:
*
*/
public function getHeight() {
}
/**
* redimenciona segun el alto
*
* @version 0.2
* @author Lucas M. Sastre
* @access Public
* @name resizeToHeight
*
* @param integer $height
*
* Modificado:
*
*/
public function resizeToHeight($height) {
$ratio = $height / $this->getHeight();
$width = $this->getWidth() * $ratio;
$this->resize($width,$height);
}
/**
* redimenciona segun el ancho
*
* @version 0.2
* @author Lucas M. Sastre
* @access Public
* @name resizeToWidth
*
* @param integer $width
*
* Modificado:
*
*/
public function resizeToWidth($width) {
$ratio = $width / $this->getWidth();
$height = $this->getheight() * $ratio;
$this->resize($width,$height);
}
/**
* escala una imagen segun el valor pasado
*
* @version 0.2
* @author Lucas M. Sastre
* @access Public
* @name scale
*
* @param integer $scale
*
* Modificado:
*
*/
public function scale($scale) {
$width = $this->getWidth() * $scale/100;
$height = $this->getheight() * $scale/100;
$this->resize($width,$height);
}
/**
* no reduce una imagen
*
* @version 0.2
* @author Lucas M. Sastre
* @access Public
* @name noResize
*
*
* Modificado:
*
*/
public function noResize() {
//creo la transprencia para los png y gif
if(($this->image_type == IMAGETYPE_GIF) OR ($this->image_type == IMAGETYPE_PNG)) {
$transparent = imagecolorallocate($new_image, 255, 255, 255);//imagecolorallocatealpha($new_image, 255, 255, 255, 127); //imagefilledrectangle($new_image, 0, 0, $width, $height, $transparent);
}
imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $this->getWidth(), $this->getHeight(), $this->getWidth(), $this->getHeight()); $this->image = $new_image;
}
/**
* reduce una imagen
*
* @version 0.2
* @author Lucas M. Sastre
* @access Public
* @name resize
*
* @param integer $width
* @param integer $height
*
* Modificado:
*
*/
public function resize($width,$height) {
//creo la transprencia para los png y gif
/*
asi tenia mi codigo original
if(($this->image_type == IMAGETYPE_GIF) OR ($this->image_type == IMAGETYPE_PNG)) {
imagealphablending($this->image, false);
imagesavealpha($this->image,true);
$transparent = imagecolorallocate($new_image, 255, 255, 255);//imagecolorallocatealpha($new_image, 255, 255, 255, 127);
//imagefilledrectangle($new_image, 0, 0, $width, $height, $transparent);
imagefill($new_image, 0, 0, $transparent);
}
imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight());
$this->image = $new_image;*/
if($this->image_type == IMAGETYPE_PNG && $this->transparent === true){
}
imagecopyresampled($newImage, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight()); $this->image = $newImage;
}
}
?>
salu2