 <p>I was having the exactly the same issue. I was first storing the image data on a local HDD before using the function <strong>imagecreatefromjpeg()</strong> to post-process the image further. </p> <p>At certain times the locally stored image was corrupted during the store process and when called by <strong>imagecreatefromjpeg($imagePath);</strong> the PHP Warning: <strong><em>imagecreatefromjpeg(): gd-jpeg, libjpeg: recoverable error: Premature end of JPEG file occured.</em></strong> showed up.</p> <p>So to resolve the PHP warnings and to make up for the corrupted image I used a clearly defined solution in the PHP manual (<a href="http://php.net/manual/en/function.imagecreatefromjpeg.php" rel="nofollow">http://php.net/manual/en/function.imagecreatefromjpeg.php</a>) see the function <strong>LoadJpeg($imgname)</strong> </p> <p>To prevent the further failures I have focused on the reason why the data supplied to <strong>imagecreatefromjpeg()</strong> function was not integrious in the first place. In my case it was the network flood issue which was causing some images to arrive corrupted.</p> <p>Long story short, you may want to check what exactly is being supplied into <strong>imagecreatefromjpeg()</strong> function before trying to extend the base library etc..</p>