[FINISHED] to products developers

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
per
Forum Members
Forum Members
Posts: 59
Joined: Tue Apr 08, 2008 4:09 pm

[FINISHED] to products developers

Post 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);
    }
Last edited by per on Wed Sep 24, 2008 5:31 am, edited 1 time in total.
User avatar
Augustas
Forum Members
Forum Members
Posts: 241
Joined: Wed Oct 17, 2007 6:09 pm
Location: the world

Re: to products developers

Post 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.
http://FollowTheRoad.com/ - living on the road...
http://www.kligys.com/ - asmeninis blog'as...
per
Forum Members
Forum Members
Posts: 59
Joined: Tue Apr 08, 2008 4:09 pm

Re: to products developers

Post by per »

good advice!
seems a good solution.
I will use it.

Thanks!
Post Reply

Return to “Developers Discussion”