Ver Mensaje Individual
  #8 (permalink)  
Antiguo 16/10/2011, 16:06
viringas
 
Fecha de Ingreso: marzo-2011
Mensajes: 226
Antigüedad: 13 años, 1 mes
Puntos: 1
Respuesta: recuperar archivo con php

ya consegui que funcionase, mediante las funciones GD de PHP.
con html no funcionaba xq al hacer echo con php no reconocia el width y height no se xq pero bueno con una clase de php q importe consegui q funcionase a la perfeccion y se puede utilizar para modificar las imagenes a cualkier tamaño conservando el aspect ratio. os la dejo aki por si os hace falta alguna vez
clase redimensionar
Código PHP:
Ver original
  1. <?PHP
  2. class img_opt
  3. {
  4. var $max_width;
  5. var $max_height;
  6. var $path;
  7. var $img;
  8. var $new_width;
  9. var $new_height;
  10. var $mime;
  11. var $image;
  12. var $width;
  13. var $height;
  14.     function max_width($width)
  15.     {
  16.         $this->max_width = $width;
  17.     }
  18.     function max_height($height)
  19.     {
  20.         $this->max_height = $height;
  21.     }
  22.     function image_path($path)
  23.     {
  24.         $this->path = $path;
  25.     }
  26.     function get_mime()
  27.     {
  28.         $img_data = getimagesize($this->path);
  29.         $this->mime = $img_data['mime'];
  30.     }
  31.     function create_image()
  32.     {
  33.         switch($this->mime)
  34.         {
  35.             case 'image/jpeg':
  36.                 $this->image = imagecreatefromjpeg($this->path);
  37.             break;
  38.            
  39.             case 'image/gif':
  40.                 $this->image = imagecreatefromgif($this->path);
  41.             break;
  42.            
  43.             case 'image/png':
  44.                 $this->image = imagecreatefrompng($this->path);
  45.             break;
  46.         }
  47.     }  
  48.     function image_resize()
  49.         {
  50.                 set_time_limit(120);
  51.                 $this->get_mime();
  52.                 $this->create_image();
  53.                 $this->width = imagesx($this->image);
  54.                 $this->height = imagesy($this->image);
  55.                 $this->set_dimension();
  56.                 $image_resized = imagecreatetruecolor($this->new_width,$this->new_height);
  57.                 imagecopyresampled($image_resized, $this->image, 0, 0, 0, 0, $this->new_width, $this->new_height,$this->width, $this->height);
  58.                 imagejpeg($image_resized,$this->path);
  59.                        
  60.         }
  61.        
  62.         //######### FUNCTION FOR RESETTING DEMENSIONS OF IMAGE ###########
  63.         function set_dimension()
  64.         {
  65.                
  66.                 if($this->width==$this->height)
  67.                 {
  68.                     $case = 'first';
  69.                 }
  70.                 elseif($this->width > $this->height)
  71.                 {
  72.                     $case = 'second';
  73.                 }
  74.                 else
  75.                 {
  76.                      $case = 'third';
  77.                 }
  78.                
  79.                
  80.                
  81.                 if($this->width>$this->max_width && $this->height>$this->max_height)
  82.                 {
  83.                     $cond = 'first';
  84.                 }
  85.                 elseif($this->width>$this->max_width && $this->height<=$this->max_height)
  86.                 {
  87.                     $cond = 'first';
  88.                 }
  89.                 else
  90.                 {
  91.                     $cond = 'third';
  92.                 }
  93.                                
  94.                 switch($case)
  95.                 {
  96.                     case 'first':
  97.                         $this->new_width = $this->max_width;
  98.                         $this->new_height = $this->max_height;
  99.                     break;
  100.                     case 'second':
  101.                         $ratio = $this->width/$this->height;
  102.                         $amount = $this->width - $this->max_width;
  103.                         $this->new_width = $this->width - $amount;
  104.                         $this->new_height = $this->height - ($amount/$ratio);
  105.                     break;
  106.                     case 'third':
  107.                         $ratio = $this->height/$this->width;
  108.                         $amount = $this->height - $this->max_height;
  109.                         $this->new_height = $this->height - $amount;
  110.                         $this->new_width = $this->width - ($amount/$ratio);
  111.                     break;
  112.                 }
  113.                    
  114.         }
  115. }
  116.  
  117.  
  118.  
  119. ?>


y aki os pongo el codigo de ejemplo para usarla:

Código PHP:
Ver original
  1. $obj = new img_opt();
  2.     $obj->max_width(190);
  3.     $obj->max_height(100);
  4.     $obj->image_path("foto.jpg");
  5.     $obj->image_resize();