Select an image form datebase and resize it
<p>The code below will resize an image to 50*50 but whenever i select the name of the image in my database and put it like these $filename = 'folder/$imagename'; it does not work how can i fix these.</p>

<pre><code>    &lt;?php
$filename = 'folder/Aizen.jpg';

$width = 50;
$height = 50;

header('Content-type: image/jpeg');
list($width_orig, $height_orig) = getimagesize($filename);

$ratio_orig = $width_orig/$height_orig;

if ($width/$height &gt; $ratio_orig) {
   $width = $height*$ratio_orig;
} else {
   $height = $width/$ratio_orig;
}

$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($filename);

imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
imagejpeg($image_p, null, 100);
?&gt;
&lt;img src="&lt;?= $filename ?&gt;" alt="" /&gt;
</code></pre>
