0

There is plenty of information on the web about resizing an uploaded image on the server. I can't find any information about resizing it on the client instead.

I am using this PHP code to handle the upload. It works, but my web server only accepts uploads of 2 MB or smaller. Therefore, I want the client side code to resize the uploaded image to be no larger than this.

Community
  • 1
  • 1
Luigi
  • 151
  • 1
  • 11
  • For what it's worth, I disagree with the close votes, though the question should be reworded to remove the mentions of PHP. Chances are there might be a duplicate somewhere though. – o11c Jul 05 '15 at 16:52

1 Answers1

3

No. PHP is a server side language. You cannot resize images on client side with PHP.

marekful
  • 14,986
  • 6
  • 37
  • 59
  • Thanks! Is it possible with .js? – Luigi Jul 05 '15 at 15:18
  • With the new JS File API a number of file manipulations can be done on local files, but that doesn't include image resizing to my knowledge. Your best bet is to execute a batch resize of all your images (independently from your application) prior to uploading the files. – marekful Jul 05 '15 at 15:21
  • mm ok, How can I execute a batch resize? (sorry I'm not very familiar with) – Luigi Jul 05 '15 at 15:22
  • There are several image manipulation applications. I'm not too familiar with them, but I know for e.g. that you can create a batch resize action in Photoshop. – marekful Jul 05 '15 at 15:24
  • Also, there's `imagemagick`. This is a command line tool and you could write a script that processes all your images and uses imagamagick to resize them. – marekful Jul 05 '15 at 15:26
  • But I'll be not the only one that will add images, I need something very simple that resize the images automatically when someone loads a pic. and it has to work with any kind of computer so also in computers without photoshop. Is it possible? – Luigi Jul 05 '15 at 15:29
  • Consider upgrading your server and doing the image resize there centrally instead of individually on each of your users' computer. – marekful Jul 05 '15 at 15:31
  • ok, So it's impossible without upgrade (I'm not in charge to decide which server to use..) – Luigi Jul 05 '15 at 15:33
  • Relevant question about JS resize before upload: http://stackoverflow.com/questions/10333971/html5-pre-resize-images-before-uploading – marizikmund Jul 05 '15 at 22:45