Foros del Web » Programando para Internet » PHP »

Thubnails

Estas en el tema de Thubnails en el foro de PHP en Foros del Web. Buenas, he mirado montones de códigos para crear thubnails pero creo que ninguno me sirve. Yo lo que hago es subir por ftp imágenes a ...
  #1 (permalink)  
Antiguo 12/04/2008, 06:15
 
Fecha de Ingreso: enero-2008
Mensajes: 97
Antigüedad: 16 años, 3 meses
Puntos: 3
Thubnails

Buenas, he mirado montones de códigos para crear thubnails pero creo que ninguno me sirve.

Yo lo que hago es subir por ftp imágenes a la carpeta "imagenes".

Lo que me gustaría es que se crearan automáticamente thubnails de tamaño 150x230 en la carpeta "portada/imagenes".

¿Eso se puede hacer?
  #2 (permalink)  
Antiguo 12/04/2008, 08:55
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Re: Thubnails

mmm.... aki dejo una libreria de gd ((haber si sirve))

Código PHP:
<?php if (!defined('EXT')) exit;
    
    class 
Image {
        var 
$imagefile '';
        var 
$imageinfo = array();
        var 
$imagebuffer '';
        var 
$imagesource '';
        
        
        function 
info($file) {
            if (!
is_file($file))
            {
                return;
            }
            
            
            
$ext strtolower(substr($filestrrpos($file'.') + 1));
            if (!
preg_match('/^(jpe?g|png|gif)$/is'$ext))
            {
                return;
            }
            
            if (!
function_exists('getimagesize'))
            {
                return;
            }
            
$data getimagesize($file);
            
            if (
is_array($data))
            {
                return array(
                    
'extension' => $ext,
                    
'width' => $data[0],
                    
'height' => $data[1],
                    
'mime' => $data['mime'],
                    
'size' => filesize($file)
                );
            }
        }
        
        
        function 
_image_open($file) {
            if (!
is_file($file))
            {
                return;
            }
            
            
$this->imageinfo $this->info($file);
            
$fn 'imageCreateFrom' .
                    
str_replace('jpg''jpeg'$this->imageinfo['extension']);
            
            
$this->imagesource $fn($file);
            
$this->imagefile $file;
        }
        function 
_image_close($out$q 75) {
            
$fn 'image' str_replace('jpg''jpeg',
                    
$this->imageinfo['extension']);
            
            if (
preg_match('/^jpe?g$/is'$this->imageinfo['extension']))
            {
                
$fn($this->imagebuffer$out$q);
            }
            else
            {
                
$fn($this->imagebuffer$out);
            }
            
            
imagedestroy($this->imagesource);
            
imagedestroy($this->imagebuffer);
        }
        
        
        
        
        
        function 
_image_apply_alpha($r 0$g 0$b 0$alpha 127) {
            if (
$this->imageinfo['extension'] == 'png')
                {
                
$this->imageinfo['alpha'] = imageColorAllocateAlpha($this->imagebuffer,
                            
$r$g$b$alpha);
                
imagealphablending($this->imagebufferFALSE);
                
imagefilledrectangle($this->imagebuffer00,
                        
imagesx($this->imagebuffer), imagesy($this->imagebuffer),
                        
$this->imageinfo['alpha']);
                
                
imagealphablending($this->imagebufferTRUE);
                
imagesavealpha($this->imagebufferTRUE);
            }
        }
        
        
        
        
        function 
resize($input$output$width$height) {
            
$this->_image_open($input);
            
$this->_image_source_resize($width$height);
            
$this->_image_close($output);
        }
        function 
_image_source_resize($width$height) {
            
$this->imagebuffer imagecreatetruecolor($width$height);
            
            
$this->_image_apply_alpha();
            
            
imagecopyresampled($this->imagebuffer,
                    
$this->imagesource0000,
                    
$width$height$this->imageinfo['width'], $this->imageinfo['height']);
        }
        
        
        
        
        function 
rotate($input$output$deg 90) {
            
$this->_image_open($input);
            
$this->_image_source_rotate($deg);
            
$this->_image_close($output);
        }
        function 
_image_source_rotate($deg$bg 0x000000) {
            if (!
function_exists('imageRotate'))
            {
                return;
            }
            
$this->imagebuffer =
                    
imageRotate($this->imagesource$deg$bg);
        }
        
        
        
        
        
        function 
thumb($input$output$width$height FALSE) {
            if (
$height === FALSE)
            {
                
$height $width;
            }
            
            
            
$this->_image_open($input);
            
$test max($width $this->imageinfo['width'],
                    
$height $this->imageinfo['height']);
            
            
            
$this->_image_source_resize($this->imageinfo['width'] * $test,
                    
$this->imageinfo['height'] * $test);
            
            
            
$x round(($this->imageinfo['width'] * $test $width) / 2);
            
$y round(($this->imageinfo['height'] * $test $height) / 2);
            
            
$this->imagesource $this->imagebuffer;
            
            
$this->_image_source_copy($width$height$x$y);
            
$this->_image_close($output);
        }
        
        
        function 
scale($input$output$width$height FALSE) {
            
$this->_image_open($input);
            
            
            if (
$height === FALSE)
            {
                
$height  round(($width $this->imageinfo['height']) / 1000);
                
$width round(($width $this->imageinfo['width']) / 1000);
            }
            else {
                
$test $this->imageinfo['height'] / $this->imageinfo['width'];
                
                if (
$test $height $width)
                {
                    
$width = (int)min($width$this->imageinfo['width']);
                    
$height = (int)round($width $test);
                }
                else {
                    
$height = (int)min($height$this->imageinfo['height']);
                    
$width = (int)round($height $test);
                }
            }
            
            
$this->_image_source_resize($width$height);
            
$this->_image_close($output);
        }
        
        
        
        
        function 
crop($input$output$width$height$x 0$y 0) {
            
$this->_image_open($input);
            
$this->_image_source_copy($width$height$x$y);
            
$this->_image_close($output);
        }
        function 
_image_source_copy($width$height$x 0$y 0) {
            
$this->imagebuffer imageCreateTrueColor($width$height);
            
$this->_image_apply_alpha();
            
            
imagecopy($this->imagebuffer$this->imagesource,
                    
00$x$y$width$height);
        }
    }
?>

haber si te soluciona


$img = new Image;
$img->thumb('gde.jpg', 'thumb-gde.jpg', 150, 230);
  #3 (permalink)  
Antiguo 12/04/2008, 09:47
 
Fecha de Ingreso: enero-2008
Mensajes: 97
Antigüedad: 16 años, 3 meses
Puntos: 3
Re: Thubnails

Gracias por la ayuda, aunque la verdad es que no se como utilizar ese código...
  #4 (permalink)  
Antiguo 12/04/2008, 10:00
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Re: Thubnails

mira.... copia la libreria en archivo PHP... la guardas como image.class.php ((o komo kieras))

la pones dentro del servidor, junto a tus PHP...
luego, la incluyes en el parser del PHP ((osea, el codigo ke haces...))

SOLO una ves, y al principio...
PEGAS tambien, este codigo

Código PHP:
define('EXT','.php');
require_once(
'image.class.php'); // o komo le haya puesto...

$img = new Image;


//
// ahora, cade ves ke kieras hacer una miniatura ((siempre y cuando tengas GD2))
// usa este ejemplo, para explicartelo....
//
$img->thumb('gde.jpg''thumb-gde.jpg'150230); 

PDTA: echate una leida al manual de PHP, :D ... animo!
  #5 (permalink)  
Antiguo 12/04/2008, 16:06
 
Fecha de Ingreso: enero-2008
Mensajes: 97
Antigüedad: 16 años, 3 meses
Puntos: 3
Re: Thubnails

Tardaré un tiempo en aprender a usar esto, pero gracias.
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 15:01.