P +886 90 537 8918 | E hello@bdigital.asia

Insights

Uploading images from iOS on your Laravel site

If you have a Laravel-based site or web based application with an image upload form you may have run into one or more issues when saving images uploaded from the iOS photos or camera app. So here we will run you through a few simple things you can do that will limit exceptions when uploading photos and also ensure that images are stored correctly.

Check your filesize

By default, PHPs maximum upload file size is 2M - this is far too small for most mobile captured images. iPhones in particular are equipped with high quality cameras and even with the good compression they offer will often be larger than this limit.

You can increase your limit by editing the following lines in your php.ini to between 5M and 10M:

post_max_size = 10M 
upload_max_filesize = 8M

Make sure libjpeg is intalled

If Laravel gives you the error Unable to init from given binary data - particularly if you are already using Intervention - you may not have the libjpeg library installed on your server. This is a library used for the manipulation of Jpeg images. To install this library on an Ubuntu server use the following command:

sudo apt-get install libjpeg-dev

Use Intervention Image for iOS images

If you have managed to get your iOS images uploading already, but you are finding the issue you are having is that the uploaded images are rotated, or have incorrect orientation, then you should be using Intervention to handle your uploaded images.

Intervention is PHP image handling library that slots nicely into Laravel with easy to use facades.

You can see more about Intervention at their github page:

https://github.com/Intervention/image

To install Intervention into your project using composer:

php composer require intervention/image

To utilize Intervention Image in your class:

<?php

use Intervention\Image\Facades\Image;

To handle and correct the orientation of your uploaded image:

$image = Image::make($file->path()); 
$image->orientate();
$img->save($path);

The library can also easily assist you with other tasks such as resizing, rotation, and cropping.

And that's it, if you are getting stuck with Image handling or manipulation on your site and this post has been helpful, or you would like to work with us then feel free to contact us.


Insights

The case for a common web platform for the public sector in Taiwan

 

Read More

A guide to flexible working

 

Read More

The Case Against Shopify

 

Read More