Swaz's avatar
Level 20

Anyone use URL based image manipulation?

I'm looking into image uploads with Laravel 5.3. I really like the simplicity of being able to do the following:

$image = $request->file('avatar')->store('path');

But 99% of the time, I want to do some sort of image manipulation, so I end of having to do something like this instead:

$image = Image::make($request->file('avatar'));

$image->fit(800, 800)->save('/path/avatar-lg.jpg');
$image->fit(400, 400)->save('/path/avatar-md.jpg');
$image->fit(100, 100)->save('/path/avatar-sm.jpg');

I stumbled across URL based image manipulation and thought it looked interesting, but I've never heard of it until now.

Has anyone used this before? Is there a general preference in the community to do one over the other, and why is that?

Any additional insight would be great.

0 likes
7 replies
ohffs's avatar

I've used it a bit - works very well. I guess you wouldn't want to use it if you know you always want to create maybe a large/mid/thumb size image up-front and you know the dimensions or you have some other particular needs. There are commercial versions that act as CDN's too - like imgix and cloudimage.

zachleigh's avatar

I use it. Its great. I usually make methods on the image model returning filter urls so in my blade views, I can do something like this:

$image->thumbnail()

It doesn't get much more readable than that.

1 like
martinbean's avatar

@Swaz We use URL-based image manipulation at work, but I don’t like it. It was implemented before I joined and don’t like the thought that people can just hit the URL and cause processing to happen in my architecture. Just seems a bit of an entry point for tying up processes from a nefarious user.

I much prefer generating pre-defined sizes and serving them up as appropriate.

Swaz's avatar
Level 20

@zachleigh Do you have any concerns with storing the original images on the server? Or do you think it's a non-issue?

Example: If a user uploads a 5MB image for their profile photo, but it will only ever be displayed at 150x150?

I understand the rendered image will be cached, but it still feels a bit off.

Please or to participate in this conversation.