<?php
$link=file("links.txt");
foreach ($link as $url){
$savefile="pict/".basename($url);
$ch = curl_init($url);
$fp = fopen ($savefile, "w");
curl_setopt ($ch, CURLOPT_FILE, $fp);
curl_setopt ($ch, CURLOPT_HEADER, 0);
curl_exec ($ch);
curl_close ($ch);
fclose ($fp);
img_resize($savefile,$savefile,500,0); //изменяем размер. ширина 500, высота пропорциональна
}
function img_resize($src, $out, $width, $height, $color = 0xFFFFFF, $quality = 100) 
{
    if (!file_exists($src)) {
        return false;  
    }
    $size = getimagesize($src);
    $format = strtolower(substr($size['mime'], strpos($size['mime'], '/') + 1));
    $picfunc = 'imagecreatefrom'.$format;
    $gor = $width  / $size[0];
    $ver = $height / $size[1];  
    if ($height == 0) {
        $ver = $gor;
        $height  = $ver * $size[1];
    }
	elseif ($width == 0) {
        $gor = $ver;
        $width   = $gor * $size[0];
    }
    $ratio   = min($gor, $ver);
    if ($gor == $ratio)
        $use_gor = true;
    else
        $use_gor = false;
    $new_width   = $use_gor  ? $width  : floor($size[0] * $ratio);
    $new_height  = !$use_gor ? $height : floor($size[1] * $ratio);
    $new_left    = $use_gor  ? 0 : floor(($width - $new_width)   / 2);
    $new_top     = !$use_gor ? 0 : floor(($height - $new_height) / 2);
    $picsrc  = $picfunc($src);
    $picout = imagecreatetruecolor($width, $height);
    imagefill($picout, 0, 0, $color);
    imagecopyresampled($picout, $picsrc, $new_left, $new_top, 0, 0, $new_width, $new_height, $size[0], $size[1]);
    imagejpeg($picout, $out, $quality);
    imagedestroy($picsrc);
    imagedestroy($picout);
    return true;
}
?>