You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
intro: Statamic uses [Glide](https://glide.thephpleague.com) to manipulate images – from resizing and cropping to adjustments (like sharpness and contrast) and image effects (like pixelate and sepia).
6
+
---
7
+
## Route
8
+
The route controls where your Glide images will be served.
9
+
10
+
```php
11
+
'image_manipulation' => [
12
+
'route' => 'img'
13
+
]
14
+
```
15
+
16
+
By default your Glide images will be served from `'/img/...'` but you are free to change that. Perhaps if you intend to have some actual images stored in the `img` directory.
17
+
18
+
:::tip
19
+
This route setting may become irrelevant when using customizing [caching options](#caching) explained further down this page.
20
+
:::
21
+
22
+
## Presets
23
+
24
+
Glide Presets are pre-configured manipulations that will be automatically generated when new image assets are uploaded. These presets are managed in `config/statamic/assets.php` as an array that holds a list of named presets and their desired parameters.
All standard Glide API parameters are available for use in presets. (Not the tag aliases like `width`. You'll need to use `w`.)
36
+
37
+
Each named preset can be referenced with the `preset` parameter on the [Glide tag][glide-tag] and since all transformations and manipulations are performed at time of upload, there shouldn't be any additional overhead on the initial request.
Out of the box, Glide will "just work". However you may want to adjust its caching methods for better performance.
52
+
53
+
In the context of Glide, the "source" is the filesystem where the original images are kept, and the "cache" is the filesystem where it saves the manipulated images.
54
+
55
+
### Default (Dynamic)
56
+
57
+
The default behavior is for the cache to be "disabled" or "dynamic".
58
+
59
+
```php
60
+
// config/statamic/assets.php
61
+
'image_manipulation' => [
62
+
'route' => 'img',
63
+
'cache' => false,
64
+
]
65
+
```
66
+
67
+
From a user's point of view, the "cache" is disabled, however technically it's just located at `storage/statamic/glide`.
68
+
69
+
The [Glide tag][glide-tag] will output URLs to the configured Glide [route](#route). When one of these URLs are visited, Statamic will use Glide to perform the transformation.
70
+
71
+
:::tip
72
+
When using this method, since the Glide tag only needs to generate URLs, the load time of the page will be faster, but the initial load time of each image request will be slower.
73
+
:::
74
+
75
+
### Custom Path (Static)
76
+
77
+
The next level of caching would be to specify a custom, publicly accessible location for the images to be generated.
78
+
79
+
```php
80
+
// config/statamic/assets.php
81
+
82
+
'image_manipulation' => [
83
+
'route' => 'img',
84
+
'cache' => true,
85
+
'cache_path' => public_path('img'),
86
+
]
87
+
```
88
+
89
+
When using this setting, the [Glide tag][glide-tag] will _actually generate_ the images instead of just outputting a URL.
90
+
91
+
Since the images are generated to a publicly accessible location, the next time a user visits the image URL, the static image would be served directly by the server, and would not need to be touched by PHP or Statamic.
92
+
93
+
:::tip
94
+
When using this method, since the Glide tag has to generate the images, the initial load time of the page will be slower.
95
+
:::
96
+
97
+
### Custom Disk (CDN)
98
+
99
+
You may choose to save your cached Glide images to somewhere CDN based, like Amazon S3 or DigitalOcean Spaces. Instead of specifying `true` as mentioned above, you can point to a filesystem disk.
Make sure that the `visibility` is `public` and that the `url` points to the correct location.
129
+
:::
130
+
131
+
:::warning
132
+
Don't use the same disk or bucket as your source images. If you were you to clear your Glide cache (e.g. when using the `glide:clear` command) the whole disk will be emptied.
133
+
:::
134
+
135
+
## Path Cache Store
136
+
137
+
Before Glide tries to generate an image, it will look into the filesystem to determine whether the image has already been generated. This will prevent the need for the image to be needlessly re-generated.
138
+
139
+
However, when using the [Custom Disk CDN](#custom-disk-cdn) caching option with a service like Amazon S3 for example, Glide will need to make an API call just to be able to check if a file exists. This would cause a slowdown.
140
+
141
+
To alleviate this problem, Statamic will keep track of whether the images have already been generated in its own separate cache.
142
+
143
+
This cache is separate from your application cache. Running `php artisan cache:clear` will **not** clear this Glide cache. This allows the Glide cache to persist through deployments or other scenarios where you might clear your application cache. It will be cleared when running `php please glide:clear`.
144
+
145
+
By default, this cache will be located in your filesystem with the storage directory.
146
+
147
+
If you would like to customize it, you can create a new store named `glide` in your `config/cache.php` configuration file. For example:
148
+
149
+
```php
150
+
'stores' => [
151
+
'file' => [
152
+
'driver' => 'redis',
153
+
'connection' => 'glide',
154
+
],
155
+
]
156
+
```
157
+
158
+
## Clearing the cache
159
+
160
+
You may manually clear the Glide cache by running the following command:
161
+
162
+
```
163
+
php artisan glide:clear
164
+
```
165
+
166
+
This will **delete all the files** within your Glide cache filesystem location, as well as clearing the [path cache](#path-cache-store).
Copy file name to clipboardExpand all lines: content/collections/tags/glide.md
+128-41
Original file line number
Diff line number
Diff line change
@@ -124,6 +124,45 @@ filters:
124
124
type: string
125
125
description: >
126
126
Applies a filter effect to the image. Accepts `greyscale` or `sepia`.
127
+
other:
128
+
-
129
+
name: preset
130
+
type: string
131
+
description: >
132
+
Applies a [preset manipulation](/image-manipulation#presets) as defined in the config.
133
+
-
134
+
name: mark
135
+
type: string
136
+
description: >
137
+
The source of a [watermark](#watermarks).
138
+
-
139
+
name: markw
140
+
type: string
141
+
description: The width of the watermark.
142
+
-
143
+
name: markh
144
+
type: string
145
+
description: The height of the watermark.
146
+
-
147
+
name: markfit
148
+
type: string
149
+
description: The fit of the watermark. [See Glide docs](https://glide.thephpleague.com/2.0/api/watermarks/#fit-markfit)
150
+
-
151
+
name: markx
152
+
type: string
153
+
description: How far the watermark is away from the left and right edges.
154
+
-
155
+
name: marky
156
+
type: string
157
+
description: How far the watermark is away from the top and bottom edges.
158
+
-
159
+
name: markpad
160
+
type: string
161
+
description: How far the watermark is away from all edges. A shortcut for using markx and marky.
162
+
-
163
+
name: markpos
164
+
type: string
165
+
description: Sets where the watermark is positioned. Accepts `top-left`, `top`, `top-right`, `left`, `center`, `right`, `bottom-left`, `bottom`, `bottom-right`. Default is `bottom-right`.
127
166
variables:
128
167
-
129
168
name: url
@@ -137,21 +176,55 @@ variables:
137
176
name: height
138
177
type: integer
139
178
description: The height of the resized image.
179
+
-
180
+
name: asset data
181
+
type: mixed
182
+
description: If your source was an asset, you will also have all of its fields available. e.g. `alt`
140
183
id: b70a3d9a-6605-446e-b278-de99ba561fe0
141
184
---
142
-
## Overview
185
+
## Setting up Glide
186
+
Glide is ready to go out of the box with no setup required. However, you may customize its behavior. You can read about it on the [image manipulation](/image-manipulation) page.
143
187
144
-
The Glide tag leverages the fantastic [Glide](http://glide.thephpleague.com/) PHP library to give you on-demand image manipulation, similar to cloud image processing services like [Imgix](https://www.imgix.com/) and [Cloudinary](https://cloudinary.com/).
188
+
## Basic Usage
145
189
190
+
Manipulate images by passing an image [source](#sources) and adding the desired [parameters](#parameters) like `height`, `crop`, or `quality`.
You may also use the tag pair to loop over multiple sources. For example, you may provide it with an `assets` field.
242
+
243
+
```
244
+
{{ glide :src="multiple_assets" width="600" }}
245
+
...
246
+
{{ /glide }}
166
247
```
167
248
168
-
## Presets
249
+
:::tip
250
+
The tag pair is also available as `{{ glide:generate }}`. You may need to use this version if you're using [Blade](#usage-in-blade).
251
+
:::
169
252
170
-
Glide Presets are pre-configured manipulations that will be automatically generated when new image assets are uploaded. These presets are managed in `config/statamic/assets.php` as an array that holds a list of named presets and their desired parameters.
253
+
:::tip
254
+
Normally, the Glide tag only generates a URL. The image itself is generated when the URL is visited. When using the tag pair, your Glide images will be generated when the page is rendered. This will result in an initial longer load time.
Rather than using the `src` parameter, you may choose to use a variable name as the second part of the tag.
261
+
262
+
```
263
+
{{ glide:my_var w="100" }}
264
+
```
265
+
266
+
You may also use the shorthand as a tag pair:
267
+
268
+
```
269
+
{{ glide:my_var }} ... {{ /glide:my_var }}
177
270
```
178
271
179
-
All [parameters](#parameters) are available for use in presets.
180
272
181
-
Each named preset can be referenced with the `preset` tag parameter and since all transformations and manipulations are performed at time of upload, there shouldn't be any additional overhead on the initial request.
273
+
## Watermarks
182
274
183
-
**Example:**
275
+
You may use Glide's [watermarking feature](https://glide.thephpleague.com/2.0/api/watermarks/) by passing in a [source](#sources) to the `mark` parameter, and then manipulate it using the various watermark parameters (`markw`, `markh`, `markfit`, etc).
You don't need to worry about setting up a watermark filesystem yourself. Statamic will take care of that automatically based on the source you provide.
283
+
:::
284
+
285
+
286
+
## Usage in Blade
287
+
288
+
To use the Glide tag within Blade, you should use the `generate` tag, which follows the same rules as the [tag pair](#tag-pair).
You should use a `@foreach` loop even if you are only providing a single source.
297
+
193
298
## Focal Point Cropping
194
299
195
300
Focal point cropping helps ensure the important bits of an image stay in the bounds of any crops you perform.
@@ -240,21 +345,3 @@ images:
240
345
<imgsrc="/img/image.jpg?w=600" />
241
346
<imgsrc="/assets/image.svg" />
242
347
```
243
-
244
-
## Serving Cached Images Directly
245
-
246
-
The default Glide tag behavior is to simply output a URL. When a URL is visited, Glide analyzes the URL and manipulates the image. However, if there are a lot of manipulations on any given page request, the total execution time can soon start to add up.
247
-
248
-
You can avoid these slowdowns by generating static images. Your server will load images directly instead of handing the work over to the Glide process each time. You can enable this behavior in your assets config file.
249
-
250
-
```php
251
-
// config/statamic/assets.php
252
-
253
-
'cache' => true,
254
-
```
255
-
256
-
## Using Glide with Locales
257
-
258
-
When using Glide with multiple locales, the generated image path will include the proper `site_root` as dictated by the locale, but the actual asset will be stored wherever you have set the `cache_path`.
259
-
260
-
To serve these assets when on a localized version, you'll need to create a symlink from your `/$locale/cache_path` to `cache_path`.
0 commit comments