PLATFORM
  • Tails

    Create websites with TailwindCSS

  • Blocks

    Design blocks for your website

  • Wave

    Start building the next great SAAS

  • Pines

    Alpine & Tailwind UI Library

  • Auth

    Plug'n Play Authentication for Laravel

  • Designer comingsoon

    Create website designs with AI

  • DevBlog comingsoon

    Blog platform for developers

  • Static

    Build a simple static website

  • SaaS Adventure

    21-day program to build a SAAS

Question By
Unsolved

Intervention Image

mart-ez

May 1st, 2017 06:18 PM

Hello DevDojo community! I’m currently trying to create a Laravel 5.4 image edit and upload app using Intervention Image. My question is, how to add Intervention Image filters to select box and apply filter based on selection?

devdojo

May 4th, 2017 11:56 AM

Hey @Mart-ez :)

Hope you are doing well. You could always add the filter name to your select dropdown. So, in the select dropdown you would do something like the following:

<select name="filter">
    <option value="awesome">Awesome Filter</option>
		<option value="cool">Cool Filter</option>
</select>

Then, inside of you controller I might even do a switch statement like so:

public function applyFilter(Request $request){
		
		$img = Image::make('foo.jpg');
		
    switch($request->filter){
		
		    case 'awesome':
				    $img->filter(new AwesomeFilter(45));
            break;
						
			 case 'cool':
				    $img->filter(new CoolFilter(45));
            break;
						
				default:
				    break;
						
		}
		
		$img->save();
}

You can learn more about applying filters here on the Intervention documentation: http://image.intervention.io/api/filter

Hope that helps :)

Thanks.

devdojo

May 4th, 2017 11:57 AM

Sorry the formatting might have gotten a little messed up in the last code block.

mart-ez

May 5th, 2017 04:08 PM

It worked brilliantly. Thanks for your help :)