Foros del Web » Programando para Internet » PHP »

PHP Imagick

Estas en el tema de PHP Imagick en el foro de PHP en Foros del Web. Hola, quería preguntarles como funciona esto. Bueno, les cuento un poquito. Estoy haciendo una página web de arriendos y la estaba haciendo con un lightbox ...
  #1 (permalink)  
Antiguo 11/10/2011, 16:49
 
Fecha de Ingreso: octubre-2011
Mensajes: 1
Antigüedad: 12 años, 6 meses
Puntos: 0
Pregunta PHP Imagick

Hola, quería preguntarles como funciona esto. Bueno, les cuento un poquito.

Estoy haciendo una página web de arriendos y la estaba haciendo con un lightbox las imágenes (galería) pero es muy tedioso hacer las imágenes pequeñas. Con tal que me recomendaron esto (no sé como se llama jeje) para hacer las imágenes, pero no sé como funciona y quisas ustedes me ayuden ^^

Muy bueno el foro, varias veces me ha respondido más de alguna pregunta, pero no me registraba jeje hasta que me avispé y lo hice ^^


Saludos, un abrazo.
  #2 (permalink)  
Antiguo 11/10/2011, 18:04
Avatar de mcun  
Fecha de Ingreso: octubre-2010
Ubicación: tras la pantalla
Mensajes: 466
Antigüedad: 13 años, 6 meses
Puntos: 55
Respuesta: PHP Imagick

que te recomendaron ????
  #3 (permalink)  
Antiguo 12/10/2011, 07:20
Avatar de DeeR  
Fecha de Ingreso: diciembre-2003
Ubicación: Santiago
Mensajes: 520
Antigüedad: 20 años, 4 meses
Puntos: 17
Respuesta: PHP Imagick

Hola JavierCoreezx

Hay muchas formas de hacer un thumb en PHP, pero lo más común es utilizar GD en vez de ImageMagick.

En general, lo que se hace, es obtener un ratio de proporción, entre las dimensiones actuales y las nuevas, luego se hace una nueva imágen y copiamos la imágen anterior con la función imagecopyresampled.

Hay varios ejemplos en el foro como en la red, de todas formas te dejo mi función (apuntes de gd)


Código PHP:
<?php

// Function by deerme.org
function imagethumb($img,$width_new=100,$savepath false)
{
        if ( !
is_file$img  )  )
        {
                throw new 
Exception('Image ('.$img.') not found.');
                return 
false;
        }
        
// Max Height
        
$height_max=1024;
        
$imginfo getimagesize($img);
        if ( !
$imginfo  )
        {
                throw new 
Exception('The file '.$img.' it is not a valid image.');
                return 
false;
        }
        switch( 
$imginfo  )
        {
                case 
$imginfo[2] == :
                        
$imggd imagecreatefromgif($img);
                break;

                case 
$imginfo[2] == :
                        
$imggd imagecreatefromjpeg($img);
                break;

                case 
$imginfo[2] == :
                        
$imggd imagecreatefrompng($img);
                break;
        }
        
$ratio = ($imginfo[0]/$width_new);
        
$height_new = (int)($imginfo[1] / $ratio);

        if(
$height_new>$height_max)
        {
            
$width_new = (int) ($height_max*$width_new/$height_new);
            
$height_new $height_max;
        }
        
        
$imggdthumb imagecreatetruecolor($width_new,$height_new); 
        
imagecopyresampled($imggdthumb$imggd0000$width_new$height_new$imginfo[0], $imginfo[1]); 
        
        if ( 
$savepath )
        {
            if ( 
is_writabledirname($savepath )) )
            {
                
imagejpeg($imggdthumb,$savepath,100);
                
imagedestroy($imggdthumb);
                return 
$savepath;
            }
            else
            {
                throw new 
Exception('The path ('.$savepath.') is not writable.');
                return 
false;
            }
        }
        else
        {
            
header("Content-type: image/jpeg");
            
imagejpeg($imggdthumb,false,100);
            
imagedestroy($imggdthumb);
            return 
true;            
        }
        
}

imagethumb("d:/tmp/cbitmap.png",128,"d:/tmp/cbitmap_thumb.jpg");
Saludos

Etiquetas: imagenes, imagick, miniaturas
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 18:04.