How to resize selected image from database?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • simon2x1
    New Member
    • Dec 2008
    • 123

    #1

    How to resize selected image from database?

    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.

    Code:
    <?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 > $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);
    ?>
    <img src="<?= $filename ?>" alt="" />
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    Does that file exist?

    Comment

    Working...