Need to clean up my code and add the ability to resize the image I have the following code:

&lt;?php
include '../../inc/config.php';

$size = isset($_REQUEST['size']) ? $_REQUEST['size'] : 'full';

$image = isset($_REQUEST['image']) ? $_REQUEST['image'] : FALSE;

if(!$image) {
    print 'Nenhuma imagem definida!';
    exit;
}

$img_hash = $PDO-&gt;prepare("SELECT url FROM missionary_photos WHERE hash = :hash");
$img_hash-&gt;bindValue(':hash', $image);
$img_hash-&gt;execute();
$img_hash = $img_hash-&gt;fetchAll(PDO::FETCH_ASSOC);
$img_url = SITE_URL.$img_hash[0]['url'];

// Get the image mime type
function get_mime_type($url)
{

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_NOBODY, 1);
curl_exec($ch);

return curl_getinfo($ch, CURLINFO_CONTENT_TYPE);

}

$mime_type = get_mime_type($img_url);

header('Content-type: '.$mime_type);

readfile($img_url);


I want to clean up the code a little bit and add the ability to resize the image using a GET or POST. Any ideas?
You can use PHP's getimagesize() function to get the MIME type.

&lt;?php
include '../../inc/config.php';

if(!isset($_REQUEST['image'])) die('Nenhuma imagem definida!');

$size = isset($_REQUEST['size']) ? $_REQUEST['size'] : 'full';
$image = $_REQUEST['image'];

$img_hash = $PDO-&gt;prepare("SELECT url FROM missionary_photos WHERE hash = :hash");
$img_hash-&gt;bindValue(':hash', $image);
$img_hash-&gt;execute();
$img_hash = $img_hash-&gt;fetchAll(PDO::FETCH_ASSOC);
$img_url = SITE_URL.$img_hash[0]['url'];

$info = getimagesize($img_url);
header('Content-type: '.$info['mime']);

readfile($img_url);