This repository has been archived by the owner on Aug 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
/
readme.txt
178 lines (111 loc) · 7.79 KB
/
readme.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
=== Fly Dynamic Image Resizer ===
Contributors: junaidbhura
Tags: media library, images, resize, dynamic, on the fly
Requires at least: 3.0
Tested up to: 6.3
Requires PHP: 5.6
Stable tag: 2.0.8
Dynamically create image sizes on the fly!
== Description ==
[Check out the Github Repository ♥](https://github.com/junaidbhura/fly-dynamic-image-resizer)
One of the biggest problems theme developers face is the problem of multiple image sizes. When you upload an image in the media library, WordPress automatically creates thumbnails based on **all the image sizes** you have defined using **`add_image_size()`** whether you want to use them or not. So the vast majority of the images in wp-content/uploads directory **are a waste, and are never used.** This is not the optimum way of creating image sizes.
With this plugin, you can create **as many image sizes as you want** without the guilt of unnecessary image sizes taking up your disk space!
This is because the images created using this plugin are dynamically created when the image is called for the **first time**, rather than when it is uploaded. You can also delete the cached images for each image individually, or all the cached images.
= How this plugin works =
1. You either define an image size in your code using the **`fly_add_image_size()`** function, or directly call the image size in the code
2. The admin uploads the image in the media library, but the fly dynamic images are not created
3. The user visits the page for the first time, and the image is dynamically created and is stored
4. The user visits the page again for the second time, and the stored version of the image is served
= Documentation =
Here are some functions and example code to get you started!
**fly_get_attachment_image_src( $attachment_id, $size, $crop )**
* **attachment_id** (integer)(required) : The ID of the image attachment
* **size** (string/array)(required) : Either the name of the pre-defined size defined using `fly_add_image_size`, or an array with the width and height. Ex: array( 500, 500 )
* **crop** (boolean/array)(optional) : Whether the image should be cropped, or the crop position
Returns an array:
`array(
'src' => string,
'width' => integer,
'height' => integer
)`
**fly_get_attachment_image( $attachment_id, $size, $crop, $attr )**
* **attachment_id** (integer)(required) : The ID of the image attachment
* **size** (string/array)(required) : Either the name of the pre-defined size defined using `fly_add_image_size`, or an array with the width and height. Ex: array( 500, 500 )
* **crop** (boolean/array)(optional) : Whether the image should be cropped, or the crop position
* **attr** (array)(optional) : An array of attributes. Ex: `array( 'alt' => 'Alt text', 'title' => 'Title text', 'class' => 'my-class', 'id' => 'my-id' )`
Returns a HTML IMG element string:
`<img src="http://yoursite.com/wp-content/uploads/fly-images/10/your-image-500x500-c.jpg" width="500" height="500" alt="Alt text" />`
= Example 1: Pre-defined Image Sizes =
In this method, you define as many image sizes as you want in your **functions.php** file.
`if ( function_exists( 'fly_add_image_size' ) ) {
fly_add_image_size( 'home_page_square', 500, 500, true );
fly_add_image_size( 'home_page_square_2x', 1000, 1000, true );
fly_add_image_size( 'cropped_top_left', 1000, 1000, array( 'left', 'top' ) );
}`
Now, lets get the post thumbnail using the image sizes we just defined:
`<?php echo fly_get_attachment_image( get_post_thumbnail_id(), 'home_page_square' ); ?>`
Here's another way you can do this:
`<?php $image = fly_get_attachment_image_src( get_post_thumbnail_id(), 'home_page_square' ); echo '<img src="' . $image['src'] . '" width="' . $image['width'] . '" height="' . $image['height'] . '" />'; ?>`
Let's get the image from our example above which has a crop position defined:
`<?php echo fly_get_attachment_image( get_post_thumbnail_id(), 'cropped_top_left' ); ?>`
= Example 2: Dynamic Image Sizes =
Lets get the post thumbnail using some dynamic image sizes:
`<?php echo fly_get_attachment_image( get_post_thumbnail_id(), array( 500, 500 ), true ); ?>`
Here's another way you can do this:
`<?php $image = fly_get_attachment_image_src( get_post_thumbnail_id(), 'home_page_square', array( 500, 500 ), true ); echo '<img src="' . $image['src'] . '" width="' . $image['width'] . '" height="' . $image['height'] . '" />'; ?>`
Lets get the post thumbnail cropped from the bottom right:
`<?php echo fly_get_attachment_image( get_post_thumbnail_id(), array( 500, 500 ), array( 'right', 'bottom' ) ); ?>`
= A note on Crop Positions =
Crop positions are set using an array. The first parameter of the array needs to be the x-axis crop and the second parameter needs to be the y-axis crop. This feature **will not** work the other way around.
For example:
✓ `fly_get_attachment_image( get_post_thumbnail_id(), array( 500, 500 ), array( 'right', 'bottom' ) )` Will work! :)
✘ `fly_get_attachment_image( get_post_thumbnail_id(), array( 500, 500 ), array( 'bottom', 'right' ) )` Will not work! :(
= Detailed Documentation =
Check out the GitHub repository's Wiki page for the full documentation: [https://github.com/junaidbhura/fly-dynamic-image-resizer/wiki](https://github.com/junaidbhura/fly-dynamic-image-resizer/wiki)
== Installation ==
Upload 'fly-dynamic-image-resizer' to the '/wp-content/plugins/' directory
Activate the plugin through the 'Plugins' menu in WordPress
Create dynamic image sizes in your PHP code!
== Screenshots ==
1. The Tools page
2. Delete individual images' cached fly images
== Changelog ==
= 2.0.8 =
* Fix error for WP_Filesystem in some edge cases [#38](https://github.com/junaidbhura/fly-dynamic-image-resizer/issues/40)
= 2.0.7 =
* Fix file extensions in edge cases [#38](https://github.com/junaidbhura/fly-dynamic-image-resizer/issues/38)
= 2.0.6 =
* New filter to potentially modify image path to work better with optimization plugins [#33](https://github.com/junaidbhura/fly-dynamic-image-resizer/issues/33)
= 2.0.5 =
* Better multi-site support [#19](https://github.com/junaidbhura/fly-dynamic-image-resizer/issues/19)
= 2.0.4 =
* Performance improvements [#15](https://github.com/junaidbhura/fly-dynamic-image-resizer/issues/15)
= 2.0.3 =
* Added two new helper functions to get previously defined image sizes [#14](https://github.com/junaidbhura/fly-dynamic-image-resizer/issues/14)
= 2.0.2 =
* Better handling of file names with decimals [#10](https://github.com/junaidbhura/fly-dynamic-image-resizer/issues/10)
= 2.0.1 =
* Removed image optimization [https://github.com/junaidbhura/fly-dynamic-image-resizer/releases/tag/2.0.1](https://github.com/junaidbhura/fly-dynamic-image-resizer/releases/tag/2.0.1)
= 2.0.0 =
* Complete re-factor of the plugin using better coding practices, standards and unit tests.
* Image optimization has finally arrived - sort of. You'll still need to install the utilities on your server before it can start working. More info [here](https://github.com/junaidbhura/fly-dynamic-image-resizer/wiki/Optimization).
* New WP CLI commands to manipulate Fly images. More info [here](https://github.com/junaidbhura/fly-dynamic-image-resizer/wiki/WP-CLI).
* Full release details: [https://github.com/junaidbhura/fly-dynamic-image-resizer/releases/tag/2.0.0](https://github.com/junaidbhura/fly-dynamic-image-resizer/releases/tag/2.0.0)
= 1.0.5 =
* Added support for crop positions. Images can now be cropped from the top, left, right, bottom or the default: center.
* Added new hook 'fly_image_created'.
= 1.0.4 =
* Check for an error in get_attachment_image_src() . Props [christopherrolfe198](https://github.com/christopherrolfe198).
= 1.0.3 =
* Added new filter 'fly_dir_path'.
= 1.0.2 =
* Fixed IIS URLs.
= 1.0.1 =
* Fixed user capabilities.
* "Full" size for fly_get_attachment_image_src now returns wp_get_attachment_image_src
= 1.0.0 =
* First stable release.