0

I am working on an upload script but I'm having some trouble with uploading huge images.

Our client needs to upload files of around 20000x20000 pixels, yes, thousands. To make it even worse, his clients need to be able to hit that as well.

Now the uploading itself is not the problem, but the image needs to be loaded in the browser, so we need a small version of it.

The following code works, but it uses way too much RAM

$imgString = file_get_contents($file['tmp_name']);
$image = imagecreatefromstring($imgString);
$tmp = imagecreatetruecolor($width, $height);
$color = imagecolorallocate($tmp, 255, 255, 255);
imagefill($tmp, 0, 0, $color);
imagecopyresampled($tmp, $image, 0, 0, 0, 0, $width, $height, $oldWidth, $oldHeight);

But it takes too much RAM-memory it crashes. Our VPS (currently) only has 4gb currently, with 3,5gb allocated to Apache for testing (of course not recommended for production).

What do you recommend for this resize process instead of doing it this way? My boss doesn't really like third-party options we can't host ourselves like Uploadcare.

Dmitry Mukhin
  • 6,649
  • 3
  • 29
  • 31
Mark
  • 31
  • 1
  • 3
  • Could you just store the image full sized and change the size in the browser? – GrumpyCrouton Apr 02 '19 at 12:56
  • You could create a smaller version using canvas before it's uploaded and add it to the upload. Then you'll let the client machine do the work instead of your server. – M. Eriksson Apr 02 '19 at 12:58
  • @GrumpyCrouton that would create huge load on network connection – matri70boss Apr 02 '19 at 15:37
  • @MagnusEriksson, Thanks for the tip, have tried it all afternoon, but the browser can't handle the images that are around 20k in height and width – Mark Apr 04 '19 at 10:10
  • This is classic build vs. buy. Your boss should be comfortable with buying enough RAM then (I work for Uploadcare :) – Dmitry Mukhin Apr 07 '19 at 10:02

0 Answers0