Sheryl Roger

Sheryl Roger

  • NA
  • 11
  • 2.1k

create thumbnail from images in PHP

May 28 2015 2:53 AM
if(preg_match('/[.](jpg)$/', $filename)) {
        $im = imagecreatefromjpeg($file . $filename);
    } else if (preg_match('/[.](gif)$/', $filename)) {
        $im = imagecreatefromgif($file . $filename);
    } else if (preg_match('/[.](png)$/', $filename)) {
        $im = imagecreatefrompng($file . $filename);
    }
 
    $ox = imagesx($im);
    $oy = imagesy($im);
     
    $nx = $final_width_of_image;
    $ny = floor($oy * ($final_width_of_image / $ox));
     
    $nm = imagecreatetruecolor($nx, $ny);
  
    imagecopyresized($nm, $im, 0,0,0,0,$nx,$ny,$ox,$oy);
    
    imagejpeg($nm, $thumnailDir . $filename,100);
    $tn = '<img src="' . $thumnailDir . $filename . '" alt="image" />';
    $tn .= '<br />Congratulations. Your file has been successfully uploaded, and a thumbnail has been created.';
    echo $tn;


here is the code m using for creating a thumbnail image... but it returns me an image of 0 bytes... can any one help me with this where I am making mistake?

Answers (1)