Here is the code I am using
<?php
header("Content-type: image/jpeg");
$src = 'images/example.jpg'; // WITH THIS LINE THE CODE WORKS
//$src = 'http://www.myserver.com/images/example.jpg'; // WITH THIS LINE THE CODE DOES NOT WORK, WHEN THE IMAGES ARE IN ANOTHER SERVER
$hmax= $GET['hmax'];
$wmax= $GET['wmax'];
$quality= $GET['quality'];
$bgcol= $GET['bgcol'];
$s = $GET['s'];
$d = $GET['d'];
// read binary stream
$fp = fopen($src, 'rb') or die('Unable to open file '.$src.' for reading');
$buf = '';
while(!feof($fp))
{
$buf .= fgets($fp, 4096);
}
fclose($fp);
$src = $buf;
echo $scr;
$source = imagecreatefromstring($buf);
$orig_w=imagesx($source);
$orig_h=imagesy($source);
if ($orig_w>$wmax || $orig_h>$hmax)
{
$thumb_w=$wmax;
$thumb_h=$hmax;
if ($thumb_w/$orig_w$orig_h>$thumb_h)
$thumb_w=round($thumb_h$orig_w/$orig_h);
else
$thumb_h=round($thumb_w*$orig_h/$orig_w);
} else
{
$thumb_w=$orig_w;
$thumb_h=$orig_h;
}
if (!@$bgcol)
{
$thumb=imagecreatetruecolor($thumb_w,$thumb_h);
imagecopyresampled($thumb,$source,0,0,0,0,$thumb_w,$thumb_h,$orig_w,$orig_h);
}
else
{
$thumb=imagecreatetruecolor($wmax,$hmax);
imagefilledrectangle($thumb,0,0,$wmax-1,$hmax-1,intval($bgcol,16));
imagecopyresampled($thumb,$source, round(($wmax-$thumb_w)/2),round(($hmax-$thumb_h)/2),0,0,$thumb_w,$thumb_h,$orig_w,$orig_h);
}
// marca de agua
//if(($s==1 or $s=='1' or $d==1 or $d=='1') and ($SESSION["screen_name"]=='')){
if(($s==1 or $s=='1' or $d==1 or $d=='1') and ($GET["user"]=='')){
$watermark = imagecreatefrompng('watermark.png');
$watermark_width = imagesx($watermark);
$watermark_height = imagesy($watermark);
$dw = $thumb_w - $watermark_width;
$dh = $thumb_h - $watermark_height;
$dest_x= $dw /2;
$dest_y= $dh /2;
imagecopymerge($thumb, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, 20);
}
if (!@$quality)
$quality=100;
if($d==1 or $d=='1'){
$name = $_GET['src'];
$a = strpos($name, '/')+1;
$src1 = substr($name, $a);
imagejpeg($thumb,'download/'.$src1,$quality);
$src = 'download/'.$src1;
header('Content-Description: File Transfer');
header('Content-Type: application/force-download');
header('Content-Length: '.filesize($src));
header('Content-Disposition: attachment; filename='.basename($src));
readfile($src);
imagedestroy($thumb);
imagedestroy($watermark);
}
else{
imagejpeg($thumb,"",$quality);
imagedestroy($thumb);
imagedestroy($watermark);
}
?>