12/30/2023 0 Comments Image resize url![]() ![]() Move on to the last piece of code: return $server -> getImageResponse ($request -> getAttribute ( 'params' ), $request -> getQueryParams ()) The code block tells Glide server to look for images under the folder public/source specified by source parameter and store image cache under the folder public/cache specified by cache parameter. Now let's take a look at the code block below: $server = ServerFactory :: create () This routing rule intercepts request to URI started with img. And create an additional routing rule as shown below: $app -> get ( '/img[/) In fact, the code we are going to implement is very minimum thanks to the great package design. We have installed all the packages we need and have our application running on PHP built-in server.It is time to implement our actual code. ![]() composer require league / glide - slim #Implement resizing code We still need to pull in another package though as Slim support is out of the core package. However Glide provides Slim support the out of box, this saves us a lot of hassle. To integrate Glide with Slim, we need to make sure the image response is handled in Slim's way. #Install Glide SlimĮvery framework hands HTTP responses different ways. ![]() If you see a nice Slim welcome page, it means you have done installing Slim. Now open your default browser and hit the URL 0.0.0.0:8080. Now navigate to folder image-server, and run the command below, it will serve the installed Slim with PHP built-in server. At the time of writing this tutorial, Slim version 3.7.0 is installed by default. This command will install a skeleton Slim site under the folder image-server. composer create - project slim / slim - skeleton image - server Installing Slim is extremely easy with the power of Composer Slim happens to be a good fit as a micro-framework. While a full blown framework will definitely provide a router,but it is overkilled. Which means we probably need a router to analyse the request. The reason is that we want to provide a user with an elegant and clean way to access the image The request URI should look like. Do check it out after this tutorial if you wish to use it with other frameworks or your standalone application.Īs mentioned earlier, we are going to use Slim in this tutorial. Glide's API is very easy to use and it provides a comprehensive documentation online. Which means it is perfectly fine to use it in any PHP projects. It is worth mentioning that Glide is a framework agnostic library. The library we are using in this tutorial is called Glide.It is an easy on-demand image manipulation library with an HTTP based API.Įven though we are going to use Glide with Slim in this tutorial. That is pretty neat! #Introduction to Glide For example, you want the image with the dimensions of 200x300, all you need to do is request it via a URL and append the dimension at the end. At the end of this tutorial, you will have an image resizing server that is able to give you specific dimension upon request. In this tutorial, we will show you how to do that for your own project. You will notice its image resizing works by appending a dimension string at the end of the URL. #Dynamic image resizing via URI with Glide and Slim Dynamic image resizing via URI with Glide and Slim. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |