on my website you can upload images and I intend to allow at least 16k resolution for each upload. When displaying the image on the website I want to use a thumbnail image.

To create the thumbnail image I'm using the php code below:

<?php
    $imageUploadFile = $_FILES["passimagefile"]["tmp_name"];

    $src = imagecreatefromjpeg($imageUploadFile);   
    list( $width, $height ) = getimagesize( $imageUploadFile ); 
    $tmp = imagecreatetruecolor( $width / $height * 700, 700 ); 
    imagecopyresampled($tmp, $src, 0, 0, 0, 0, $width / $height * 700, 700, $width, $height);           
    imagejpeg($tmp, $taget_thumbnail, 75);
?>

This works perfectly fine for most smaller (1k-4k) images. The thumbnail is correctly being generated. However, when I go and try to do it with an image that is like 6k or 8k the result is suddenly wrong.

The thumbnail image is being generated however it is completely black.

Is there a way to fix this?

2

There are 2 best solutions below

3
On BEST ANSWER

There is many quirks in php-gd, often requiring a lot of trials and errors!

You might had reach an internal limit, thus try to generate your image, but resize it down before exporting, examples:

$tmp = imagescale($tmp, 1920, 1080);
$tmp = imagecrop($tmp,  ['x' => 0, 'y' => 0, 'width' => 1920, 'height' => 1080]);

// ...

imagejpeg($tmp, $taget_thumbnail, 75);

If it doesn't works, you have to consider joining many images, as tiles.


For advanced stuffs, in Linux, you can try to use the shell (from php) and imagemagick instead. http://www.imagemagick.org/Usage/text/

0
On

Finally I have found the problem after talking to the customer service of my hosting platform and it turns out that my upload limit over smtp is 20MB and therefore it doesn't work for larger files.

So I guess @NVRM's answer is the most correct and fitting.

The solution by the way would be to get a VPS Hosting instead, there I wouldn't have an upload limit..