I’m working on a project where I upload an image (jpg) and manipulate it using the PHP GD library.
I know that I can use GD functions to edit an image resource (created from imagecreatefromjpeg()) but I was wondering if there was a way I could use the file uploaded in the $_FILES array directly with the GD library. One solution I thought of was saving the uploaded file, pushing it into imagecreatefromjpeg, then deleting it afterwards.
This seems cluinky though, is there a more efficient solution?
I’m still a bit new to PHP so I’m not sure as to how files are stored in the $_FILES array. I hope I’m making sense here. Thanks.
You can simply do this:
You’ll have to use
imagecreatefromin some form or another, and you can use it directly on the uploaded file. Then just save the result of your manipulations usingimagejpeg. The uploaded file intmp_namewill we thrown away automatically.Having said that, you should save the original somewhere. It’s always good to have it around for later use.