Foros del Web » Programando para Internet » PHP »

Modificar clase thumbnail

Estas en el tema de Modificar clase thumbnail en el foro de PHP en Foros del Web. Hola, Uso una clase para generar miniaturas, subir y nombrar imagenes. Quisiera modificarla para que ademas me añada un png como marca de agua; pero ...
  #1 (permalink)  
Antiguo 19/03/2012, 05:39
Avatar de fario13  
Fecha de Ingreso: junio-2004
Ubicación: Entre Madrid y Logroño
Mensajes: 411
Antigüedad: 19 años, 10 meses
Puntos: 7
Modificar clase thumbnail

Hola,

Uso una clase para generar miniaturas, subir y nombrar imagenes. Quisiera modificarla para que ademas me añada un png como marca de agua; pero no se como hacerlo. Esta es la clase:

<?php

/**
* Thumbnail
*
* Crea una miniatura de una imagen y la guarda en un formato especifico
*
* @package
* @author Snd234
* @copyright 2008
* @version 1.0
* @access public
*/
class Thumbnail {
// informacion de la miniatura
private $thumbnail;
private $thumbnail_width;
private $thumbnail_height;

// informacion de la imagen original
private $image;
private $image_width;
private $image_height;
private $image_type;

public $error;

/**
* Thumbnail::__construct()
*
* @param mixed $source
* @return
*/
public function __construct($source) {
$image_info = getimagesize($source);

if($image_info) {
$this->image_width = $image_info[0];
$this->image_height = $image_info[1];
$this->image_type = $image_info[2];

switch($this->image_type) {
case IMAGETYPE_JPEG: {
$this->image = ImageCreateFromJPEG($source);
break;
}

case IMAGETYPE_GIF: {
$this->image = ImageCreateFromGIF($source);
break;
}

case IMAGETYPE_PNG: {
$this->image = ImageCreateFromPNG($source);
break;
}

default: {
$this->error = "Formato no soportado";
break;
}
}
}
else {
$this->error = "Formato invalido";
}
}

/**
* Thumbnail::resize()
*
* @param mixed $width
* @param integer $height
* @return void
*/
public function resize($medida, $ancho, $alto) {

// CALCULO ANCHO Y ALTO PROPORCIONALES
if ($ancho > $alto) {
$proporcion = round(($medida * 100) / $ancho);
$ancho = $medida;
$alto = round(($alto * $proporcion) / 100);
}
if ($alto > $ancho) {
$proporcion = round(($medida * 100) / $alto);
$alto = $medida;
$ancho = round(($ancho * $proporcion) / 100);
}
if ($alto == $ancho) {
$ancho = $medida;
$alto = $medida;
}
$this->thumbnail_width = $ancho;
$this->thumbnail_height = $alto;

$this->thumbnail = imagecreatetruecolor($this->thumbnail_width, $this->thumbnail_height);

imagecopyresampled(
$this->thumbnail, $this->image, 0, 0, 0, 0,
$this->thumbnail_width, $this->thumbnail_height,
$this->image_width, $this->image_height
);
}

/**
* Thumbnail::save_jpg()
*
* @param mixed $dir
* @param mixed $name
* @param integer $quality
* @return
*/
public function save_jpg($dir, $name, $quality = 100) {
$path = $dir . $name . ".jpg";
imagejpeg($this->thumbnail, $path, $quality);

imagedestroy($this->thumbnail);
}

/**
* Thumbnail::save_gif()
*
* @param mixed $dir
* @param mixed $name
* @return
*/
public function save_gif($dir, $name) {
$path = $dir . $name . image_type_to_extension(IMAGETYPE_GIF);
imagegif($this->thumbnail, $path);

imagedestroy($this->thumbnail);
}

/**
* Thumbnail::save_png()
*
* @param mixed $dir
* @param mixed $name
* @return
*/
public function save_png($dir, $name) {
$path = $dir . $name . image_type_to_extension(IMAGETYPE_PNG);
imagegif($this->thumbnail, $path);

imagedestroy($this->thumbnail);
}
}

?>

Un saludo
__________________
Bodegas La Rioja

Etiquetas: clase, imagenes, modificar, thumbnails
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 17:06.