<?php
require("../connect.php");
$url = $_GET["url"];
$width =  '300'; // maximale breite
$height = '300'; // maximale höhe
$l = mysql_real_escape_string($_GET["l"]);
$m = mysql_real_escape_string($_GET["m"]);
if($l != '') {
	$user = mysql_fetch_array(mysql_query("SELECT `photo`,`name` FROM `accounts` WHERE `name` = '".$l."'"));

	if($user["photo"] != '') {
               $url = 'http://'.$chaturl.'/pics/photos/l/'.$user["photo"].'.jpg';
      	}
}
if($m != '') {
	$user = mysql_fetch_array(mysql_query("SELECT `photo`,`name` FROM `accounts` WHERE `name` = '".$m."'"));

	if($user["photo"] != '') {
               $url = 'http://'.$chaturl.'/pics/photos/m/'.$user["photo"].'.jpg';
      	}
}
$endung = substr($url, -3); 
if ($endung != 'gif') {
header("Content-type: image/jpeg");
} else {
header("Content-type: image/gif");
}
if ($endung == 'jpg') {
$image = imagecreatefromjpeg($url);
} else if ($endung == 'png') {
$image = imagecreatefrompng($url);
}else if ($endung == 'gif') {
$image = imagecreatefromgif($url);
}

list($width_orig, $height_orig) = getimagesize($url);

if ($width_orig > $width || $height_orig > $height) {
$ratio_orig = $width_orig/$height_orig;
if ($width/$height > $ratio_orig) {
   $width = $height*$ratio_orig;
} else {
   $height = $width/$ratio_orig;
}
$image_p = imagecreatetruecolor($width, $height);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
} else {
$image_p = $image;
}
if ($endung != 'gif') {
Imagejpeg($image_p, null, 100);
} else {
Imagegif($image_p, null, 100);
}
ImageDestroy($image_p);
?>