Como que no te funciona
Acuérdate de indicar en la clase el segundo parametro, que indica que quieres que sea transparente.
Trata de esta forma para que veas que
sí funciona
Código PHP:
Ver original<?php
/**
* File: ResizePicture.php
* Author: Simon Jarvis
* Copyright: Simon Jarvis
* Date: 08/11/06
* Original link: http://www.white-hat-web-design.co.uk/articles/php-image-resizing.php
*
* Modified Date: 05/14/11
*/
class ResizePicture {
private $_image;
private $_imageType;
private $_transparent;
public function __construct($fileName=null, $transparent=false)
{
$this->setTransparent($transparent);
$this->load($fileName);
}
}
public function setTransparent($bool)
{
$this->_transparent = (boolean)$bool;
}
public function load($fileName)
{
$this->_imageType = $imageInfo[2];
if($this->_imageType == IMAGETYPE_JPEG){
}
elseif($this->_imageType == IMAGETYPE_GIF){
}
elseif($this->_imageType == IMAGETYPE_PNG){
}
}
public function save($fileName, $compression=75, $permissions=null)
{
if($this->_imageType == IMAGETYPE_JPEG){
imagejpeg($this->_image
, $fileName, $compression); }
elseif($this->_imageType == IMAGETYPE_GIF){
}
elseif($this->_imageType == IMAGETYPE_PNG){
}
chmod($fileName, $permissions); }
}
public function output()
{
if($this->_imageType == IMAGETYPE_JPEG){
}
elseif($this->_imageType == IMAGETYPE_GIF){
}
elseif($this->_imageType == IMAGETYPE_PNG){
}
}
public function getWidth()
{
}
public function getHeight()
{
}
public function getImageType()
{
switch($this->_imageType){
case IMAGETYPE_JPEG:
$imageType = 'image/jpeg';
break;
case IMAGETYPE_GIF:
$imageType = 'image/gif';
break;
case IMAGETYPE_PNG:
$imageType = 'image/png';
break;
default:
$imageType = null;
}
return $imageType;
}
public function resizeToHeight($height)
{
$ratio = $height / $this->getHeight();
$width = $this->getWidth() * $ratio;
$this->resize($width,$height);
}
public function resizeToWidth($width)
{
$ratio = $width / $this->getWidth();
$height = $this->getHeight() * $ratio;
$this->resize($width, $height);
}
public function scale($scale)
{
$width = $this->getWidth() * $scale / 100;
$height = $this->getHeight() * $scale / 100;
$this->resize($width, $height);
}
public function resize($width, $height)
{
if($this->getImageType() == 'image/png' && $this->_transparent === true){
}
imagecopyresampled($newImage, $this->_image
, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight()); $this->_image = $newImage;
}
}
?>
<html>
<head>
<style>
body{ background-color: #369; }
</style>
</head>
<body>
<?php
if(!empty($_FILES['image']) && $_FILES['image']['error'] == UPLOAD_ERR_OK
) { $image = new ResizePicture($_FILES['image']['tmp_name'], true);
$image->resizeToWidth($image->getWidth());
$original = $_FILES['image']['name'];
$image->save($original);
?>
Imagen grabada:
<img src="/<?php echo $original; ?>" />
<?php } ?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">
<input type="file" name="image" />
<input type="submit" name="submit" value="Upload" />
</form>
</body>
</html>