Page 1 of 1

[FINISHED] to products developers

Posted: Tue Sep 23, 2008 10:45 pm
by per
i want use this script to manage many thumbs size.
i created an UDT but when i used in the module i have smarty error.
could you configure to use?
i think moy be good for all the users.
thanks very much


$id_imagen = $_GET['img'];
$max = $_GET['max'];//max thumbs size

    $query = "SELECT * FROM imagen WHERE id_imagen =".$id_imagen;
    $consulta = mysql_query($query);
    $row_consulta = mysql_fetch_assoc($consulta);
   
    $imagen = "editor/producto/img/".$row_consulta['imagen'];

    //obtener datos de imagen
    $array = getimagesize($imagen);
    $ancho = $array[0];
    $alto =  $array[1];
    $tipo = $array[2];//1=gif , 2=jpg, 3=png

    // crear imagen desde original
    if($tipo == 1){
        $img = @imagecreatefromgif($imagen);
    }elseif($tipo == 2){
        $img = @imagecreatefromjpeg($imagen);
    }
   
    if($ancho < $alto){
        $porcentaje = (100 * $max) /$alto;
        $img_nueva_altura = $max;
        $img_nueva_anchura = ($ancho/100) * $porcentaje;
    }else{
        $porcentaje = (100 * $max) /$ancho;
        $img_nueva_anchura = $max;
        $img_nueva_altura = ($alto/100) * $porcentaje;
    }
     
    // crear imagen nueva
    $thumb = imagecreatetruecolor($img_nueva_anchura,$img_nueva_altura);

    // redimensionar imagen original copiandola en la imagen
    imagecopyresized($thumb,$img,0,0,0,0,$img_nueva_anchura, $img_nueva_altura,imagesx($img),imagesy($img));

    // guardar la imagen redimensionada donde indicia $img_nueva
    if($tipo == 1){
        header("Content-type: image/gif");
        imagegif($thumb);
    }elseif($tipo == 2){
        header("Content-type: image/jpeg");
        imagejpeg($thumb,"",90);
    }

Re: to products developers

Posted: Wed Sep 24, 2008 12:01 am
by Augustas
You can simply resize thumbnails with HTML tags.
This is what I mean:
1. In the CGExtensions (which controls thumb size for Products) enter the size of your biggest thumbnail you use in the website. Let's say it is 200px
2. then in your product templates you can call this thumbnail and resize with HTML commands:

Code: Select all

<img src="{$entry->file_location}/{$entry->fields.Image->thumbnail}" width="30" />
<img src="{$entry->file_location}/{$entry->fields.Image->thumbnail}" width="100" />
<img src="{$entry->file_location}/{$entry->fields.Image->thumbnail}" width="150" />
As you see I displayed the same thumbnail in 3 different dimensions.

The picture with 200px is not so big, so even the page displays it as width=30, it does not really take much more time to load, in my opinion.

Re: to products developers

Posted: Wed Sep 24, 2008 5:30 am
by per
good advice!
seems a good solution.
I will use it.

Thanks!