Would it make sense to determine image type and use coresponding `imagecreatefrom(gif|jpeg|png)` instead? This would prevent loading the entire image into memory...