Thavarith
Thavarith

Reputation: 287

Cannot make a thumbnail of the uploaded image with php

I need to make a thumbnail of an image after successfully uploaded the image file. I wrote this function but it seems doesn't work. Hope anyone could help. Thanks

function make_thumb( $src, $thumbDest, $thumbWidth ){
    $sourceImage  = imagecreatefromjpeg( $src );
    $theWidth     = imagesx( $sourceImage );
    $theHeight    = imagesy( $sourceImage );

    $thumbHeight = floor( $theHeight * ( $thumbWidth / $theWidth ) );
    $tempImage   = imagecreatetruecolor( $thumbWidth, $thumbHeight );
    imagecopyresized( $tempImage, $sourceImage, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $theWidth, $theHeight );

    imagejpeg( $tempImage, $thumbDest );
    imagedestroy( $tempImage );
    imagedestroy( $sourceImage );
}

Upvotes: 0

Views: 67

Answers (1)

Suman
Suman

Reputation: 9571

If you are on Linux, check the /var/log/httpd/error_log or /var/log/apache2/error_log to see the reason why it failed (if you have error reporting turned off.)

Also, it may due to a file permission issue. Make sure that the $thumbDest destination folder/directory is writable by the user that Apache or the web server is running as.

Upvotes: 1

Related Questions