Download the PHP package marcohern/dimages without Composer
On this page you can find all versions of the php package marcohern/dimages. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download marcohern/dimages
More information about marcohern/dimages
Files in marcohern/dimages
Package dimages
Short Description Upload images and download them in different densities and sizes
License MIT
Informations about the package dimages
dimages
Simple Image management for Laravel. Very usefull if you are developing a Laravel API for Mobile Applications, dimages can resample images depending on what the image will be used for and the devices density.
Installation
Download and install laravel.
Dimages allows images to be downloaded by the public. However, uploading images can only be done through authentication, by way of the auth:api middleware. The easiest way to achieve api authentication is to use laravel/passport. Note: laravel/passport requires a database, so make sure you have one set up.
So download, install, and configure laravel passport:
This will install passport and all it's dependencies.
You will get an output similar to:
This creates 2 grants for Signing in. The first one is a Personal access client, which we will ignore for now. The second one is a Password grand which is the one we will use to log in. So remember the second Client secret, we will use it as an API key of sorts to log into the api. Now, In the mean time, you need to create a user to log in with, lets create a seeder to add a user.
This creates the seeder class in database/seeds folder, lets add the code:
The code contains a bunch of users for testing, we can use any of those to log in. To run the seeder, run the following command:
So now we have passport working, and users to log in with. We can now use composer to install marcohern/dimages
At this point, the library is installed. But you need to install the configuration file.
Run the following command:
A list of publishables appear, pick the one labeled config.
At that moment you will see the following message output:
This means that the configuration has been deployed. Finally, by typing the following command:
A list of routes will appear. If routes with prefixes dimage, dimaages and dimagesettings appear, then the library is working and installed.
You are now ready to use the library.
Using dimages
dimages exposes endpoints that help you manage images, and download them for specific profiles and density.
To make sure to get a result in JSON format, make sure to add header Accept: application/json.
Uploading one or more images
Example
Parameters
tenant: The user or tenant of the image, it can be a code, slug, or username. such as mike or user1234.
entity: Entity of the image. such as user, user-profile or albums.
identity: Reference to the object attached to the image, such as the username or a slug. Examples: john-doe, my-album-2020-01-22.
image: (in body) Upload a file in a field called image. Content-Type must be application/x-www-form-urlencoded.
Returns
You can only upload one image per request. If you upload more than one image (with multiple requests), each image will return an index number, the first one being 0, then 1, and so on.
Downloading uploaded images
Examples
Parameters
tenant: The user or tenant of the image, it can be a code, slug, or username. such as mike or user1234.
entity: Entity of the image. such as user, user-profile or albums.
identity: Reference to the object attached to the image, such as the username or a slug. Examples: john-doe, my-album-2020-01-22.
index: (optional) the index of the image. If no index is specified, index zero (0) is used.
Returns
Returns the source image, in it's original size, as it was uploaded.
Downloading uploaded images in different sizes
Examples
Parameters
tenant: The user or tenant of the image, it can be a code, slug, or username. such as mike or user1234.
entity: Entity of the image. such as user, user-profile or albums.
identity: Reference to the object attached to the image, such as the username or a slug. Examples: john-doe, my-album-2020-01-22.
profile: The profile of the image. The profile is essentially a reference to what the image will be used for, such as, as an icon, or a cover. Essentially it defines the aspect ratio.
density: Reference to the object attached to the image, such as the username or a slug. Examples: john-doe, my-album-2020-01-22.
index: (optional) the index of the image. If no index is specified, index zero (0) is used.
Returns
The image in the appropriate size.
Configuring image sizes
The image sizes can be configured in the config/dimages.php file. There are settings to begin with.
densities: A list of densities in inches per pixel. This will used to calculate the size of any image requested with the specified density. You can add new density multipliers if you like.
profiles: A list of image sizes in pixels. It is the size of the image if the density was equal to 1 (mdpi). Sizes are calculated by multiplying the specified density with each dimension of the specified profile. In principle, you will be adding more profiles as your app requires.
Examples:
Deleting images
Examples
Parameters
tenant: The user or tenant of the image.
entity: Entity of the image.
identity: Identity.
index: (optional) the index of the image. Images with the matching index will be deleted. If not specified, all images associated with the identity will be deleted.
Other endpoints available
Installation fo Development Environment
To install dimages to develop for it, follow these steps.
- Install a new Laravel application that you will use for running and testing your development. Let's call it laravel_packages.
- In the root folder, create a packages/marcohern folder.
- In packages/marcohern folder, checkout dimages source in a dimages folder. In the end, the path to the cloned repository should be in: /path/to/your/workspace/laravel_packages/marcohern/dimages/
At this point, you must register the package in laravel:
-
Add the DimagesServiceProvider to the providers list in the config/app.php file.
-
Include the package source files in the composer.json file autoload section. Include the dimages namespace/source folder in the psr-4 list, and the Helper.php in the files list.
- Finally, run composer dump-autoload.
At this point, the package module should be working. Test it by opening the module's main route.
-
Run php artisan serve on the laravel project.
- Open a browser and access the package module with the following url: http://localhost:8000/mh/dim/api/status. This should return a 200 and a json with success = true. You are all set!