Ver Mensaje Individual
  #1 (permalink)  
Antiguo 16/02/2012, 14:59
yazo
 
Fecha de Ingreso: abril-2003
Mensajes: 363
Antigüedad: 23 años, 5 meses
Puntos: 3
Importar imagenes mediante CRON

Hola a todos!

Os voy a contar mi problema haber si me podeis ayudar a solucionarle.
Tengo en un servidor dos páginas webs, la una es la que alberga las imágenes y la otra es la que las muestra al público.
Tengo un script que las redimensiona mediante CRON (ya que no las puedo coger directamente y redimensionarlas)
El código del script es:
Código PHP:
/*
    Con CURL obtenemos la imagen de otro alojamiento
*/

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $_GET['imagen']);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
$resultado = curl_exec($ch);
$error = curl_error($ch);
curl_close($ch);


// Image Resize Script by Zipline Interactive
// http://www.gozipline.com
// http://www.gozipline.com/42,phpimageresizefunction
// [email protected]
// 02/02/2008

// This will resize an image keeping its height/width aspect ratio if you do not specify a height value.

// USAGE:

    // MAINTAIN ASPECT AND SAVE FILE.
    // This will create a new files called 'resizedImage.jpg' with a longest side resized to 600px.
    // resizeImage('../uploads/uploadedImage.jpg','resizedImage.jpg','600'); 
    
    // MATIAN ASPECT AND SHOW THE IMAGE IN THE BROWSER.
    // No other output can be shown before this image.
    // resizeImage('../images/uploadedImage.jpg','','450');
    
    // RESHAPE IMAGE WITH SET SIZES
    // This will reshape the image to the set dimensions and save as a jpg file.
    // resizeImage('uploadedImage.jpg','../images/resized/resizedImage.jpg','150','150');

function resizeImage($data, $destination = NULL, $wdt, $height = NULL){
    if(empty(
$height)){
        
$image = imagecreatefromstring($data);
        
        
// Height is nit set so we are keeping the same aspect ratio.
        
$width = imagesx($image);
        
$height = imagesy($image);

        if(
$width > $height){
            
$w = $wdt;
            
$h = ($height / $width) * $w;
            
$w = $w;
        }else{
            
$w = $wdt;
            
$h = $w;
            
$w = ($width / $height) * $w;
        }
    }else{
        
// Both width and Height are set.
        // this will reshape to the new sizes.
        
$w = $wdt;
        
$h = $height;
    }
    
$source_image = @imagecreatefromstring($data) or die('No es una imagen valida');
    
$sw = imagesx($source_image);
    
$sh = imagesy($source_image);
    
$ar = $sw/$sh;
    
$tar = $w/$h;
    if(
$ar >= $tar){
        
$x1 = round(($sw - ($sw * ($tar/$ar)))/2);
        
$x2 = round($sw * ($tar/$ar));
        
$y1 = 0;
        
$y2 = $sh;
    }else{
        
$x1 = 0;
        
$y1 = 0;
        
$x2 = $sw;
        
$y2 = round($sw/$tar);
    }
    
$slate = @imagecreatetruecolor($w, $h) or die('Dimensiones de la miniatura incorrectas');
    
imagecopyresampled($slate, $source_image, 0, 0, $x1, $y1, $w, $h, $x2, $y2);
    
// If $destination is not set this will output the raw image to the browser and not save the file
    
if(!$destination) header('Content-type: image/jpeg');
    @
imagejpeg($slate, $destination, 100) or die('Problema con los permisos del directorio');
    
ImageDestroy($slate);
    
ImageDestroy($source_image);
    if(!
$destination) exit;
    return 
true;
}

 
//Redimensionamos la imagen
 
resizeImage($resultado,'',$_GET['dimensiones']); 
Aqui le paso la ruta de la imagen (de la forma http://www.dominio.com/foto.jpg) y las dimensiones máximas, funciona correctamente, el problema es que aunque está al 100% de calidad la imagen redimensionada no se ve con calidad, se nota muchisimo la diferencia.
No se si es porque se coge mediante http, ¿conoceis algún script o sabeis como puedo hacer para cogerla por la ruta del servidor (p.ej. /ruta/de/la/carpeta/a/explorar/foto.jpg)?
¿O sabeis porque puede notarse tanto la diferencia?

Muchisimas Gracias