Version Description
Download this release
Release Info
Developer | rosell.dk |
Plugin | WebP Express |
Version | 0.2.0 |
Comparing to | |
See all releases |
Version 0.2.0
- LICENSE +674 -0
- README.md +86 -0
- README.txt +105 -0
- assets/banner-772x250.jpg +0 -0
- assets/icon-128x128.png +0 -0
- assets/icon-256x256.png +0 -0
- assets/icon.svg +27 -0
- assets/screenshot-1.png +0 -0
- convert.php +38 -0
- css/webp-express-options-page.css +88 -0
- images/drag-reorder.svg +17 -0
- js/sortable.min.js +3 -0
- js/webp-express-options-page.js +342 -0
- lib/activate.php +64 -0
- lib/deactivate.php +11 -0
- lib/helpers.php +190 -0
- lib/message.php +141 -0
- lib/options.php +466 -0
- test-run.php +254 -0
- test/focus.jpg +0 -0
- test/test.jpg +0 -0
- vendor/webp-convert-and-serve/WebPConvertAndServe.php +196 -0
- vendor/webp-convert-and-serve/autoload.php +26 -0
- vendor/webp-convert/Converters/Binaries/cwebp-fbsd +0 -0
- vendor/webp-convert/Converters/Binaries/cwebp-linux +0 -0
- vendor/webp-convert/Converters/Binaries/cwebp-mac12 +0 -0
- vendor/webp-convert/Converters/Binaries/cwebp-sol +0 -0
- vendor/webp-convert/Converters/Binaries/cwebp.exe +0 -0
- vendor/webp-convert/Converters/Binaries/test +0 -0
- vendor/webp-convert/Converters/ConverterHelper.php +260 -0
- vendor/webp-convert/Converters/Cwebp.php +246 -0
- vendor/webp-convert/Converters/Ewww.php +197 -0
- vendor/webp-convert/Converters/Exceptions/ConversionDeclinedException.php +10 -0
- vendor/webp-convert/Converters/Exceptions/ConverterFailedException.php +10 -0
- vendor/webp-convert/Converters/Exceptions/ConverterNotOperationalException.php +10 -0
- vendor/webp-convert/Converters/Gd.php +83 -0
- vendor/webp-convert/Converters/Imagick.php +76 -0
- vendor/webp-convert/Converters/Wpc.php +135 -0
- vendor/webp-convert/Exceptions/ConverterNotFoundException.php +10 -0
- vendor/webp-convert/Exceptions/CreateDestinationFileException.php +10 -0
- vendor/webp-convert/Exceptions/CreateDestinationFolderException.php +10 -0
- vendor/webp-convert/Exceptions/InvalidFileExtensionException.php +10 -0
- vendor/webp-convert/Exceptions/TargetNotFoundException.php +10 -0
- vendor/webp-convert/Exceptions/WebPConvertBaseException.php +7 -0
- vendor/webp-convert/Loggers/BaseLogger.php +26 -0
- vendor/webp-convert/Loggers/EchoLogger.php +22 -0
- vendor/webp-convert/Loggers/VoidLogger.php +14 -0
- vendor/webp-convert/WebPConvert.php +102 -0
- vendor/webp-convert/autoload.php +33 -0
- vendor/webp-on-demand/PathHelper.php +170 -0
- vendor/webp-on-demand/WebPOnDemand.php +296 -0
- vendor/webp-on-demand/autoload.php +26 -0
- webp-express.php +62 -0
LICENSE
ADDED
@@ -0,0 +1,674 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
GNU GENERAL PUBLIC LICENSE
|
2 |
+
Version 3, 29 June 2007
|
3 |
+
|
4 |
+
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
5 |
+
Everyone is permitted to copy and distribute verbatim copies
|
6 |
+
of this license document, but changing it is not allowed.
|
7 |
+
|
8 |
+
Preamble
|
9 |
+
|
10 |
+
The GNU General Public License is a free, copyleft license for
|
11 |
+
software and other kinds of works.
|
12 |
+
|
13 |
+
The licenses for most software and other practical works are designed
|
14 |
+
to take away your freedom to share and change the works. By contrast,
|
15 |
+
the GNU General Public License is intended to guarantee your freedom to
|
16 |
+
share and change all versions of a program--to make sure it remains free
|
17 |
+
software for all its users. We, the Free Software Foundation, use the
|
18 |
+
GNU General Public License for most of our software; it applies also to
|
19 |
+
any other work released this way by its authors. You can apply it to
|
20 |
+
your programs, too.
|
21 |
+
|
22 |
+
When we speak of free software, we are referring to freedom, not
|
23 |
+
price. Our General Public Licenses are designed to make sure that you
|
24 |
+
have the freedom to distribute copies of free software (and charge for
|
25 |
+
them if you wish), that you receive source code or can get it if you
|
26 |
+
want it, that you can change the software or use pieces of it in new
|
27 |
+
free programs, and that you know you can do these things.
|
28 |
+
|
29 |
+
To protect your rights, we need to prevent others from denying you
|
30 |
+
these rights or asking you to surrender the rights. Therefore, you have
|
31 |
+
certain responsibilities if you distribute copies of the software, or if
|
32 |
+
you modify it: responsibilities to respect the freedom of others.
|
33 |
+
|
34 |
+
For example, if you distribute copies of such a program, whether
|
35 |
+
gratis or for a fee, you must pass on to the recipients the same
|
36 |
+
freedoms that you received. You must make sure that they, too, receive
|
37 |
+
or can get the source code. And you must show them these terms so they
|
38 |
+
know their rights.
|
39 |
+
|
40 |
+
Developers that use the GNU GPL protect your rights with two steps:
|
41 |
+
(1) assert copyright on the software, and (2) offer you this License
|
42 |
+
giving you legal permission to copy, distribute and/or modify it.
|
43 |
+
|
44 |
+
For the developers' and authors' protection, the GPL clearly explains
|
45 |
+
that there is no warranty for this free software. For both users' and
|
46 |
+
authors' sake, the GPL requires that modified versions be marked as
|
47 |
+
changed, so that their problems will not be attributed erroneously to
|
48 |
+
authors of previous versions.
|
49 |
+
|
50 |
+
Some devices are designed to deny users access to install or run
|
51 |
+
modified versions of the software inside them, although the manufacturer
|
52 |
+
can do so. This is fundamentally incompatible with the aim of
|
53 |
+
protecting users' freedom to change the software. The systematic
|
54 |
+
pattern of such abuse occurs in the area of products for individuals to
|
55 |
+
use, which is precisely where it is most unacceptable. Therefore, we
|
56 |
+
have designed this version of the GPL to prohibit the practice for those
|
57 |
+
products. If such problems arise substantially in other domains, we
|
58 |
+
stand ready to extend this provision to those domains in future versions
|
59 |
+
of the GPL, as needed to protect the freedom of users.
|
60 |
+
|
61 |
+
Finally, every program is threatened constantly by software patents.
|
62 |
+
States should not allow patents to restrict development and use of
|
63 |
+
software on general-purpose computers, but in those that do, we wish to
|
64 |
+
avoid the special danger that patents applied to a free program could
|
65 |
+
make it effectively proprietary. To prevent this, the GPL assures that
|
66 |
+
patents cannot be used to render the program non-free.
|
67 |
+
|
68 |
+
The precise terms and conditions for copying, distribution and
|
69 |
+
modification follow.
|
70 |
+
|
71 |
+
TERMS AND CONDITIONS
|
72 |
+
|
73 |
+
0. Definitions.
|
74 |
+
|
75 |
+
"This License" refers to version 3 of the GNU General Public License.
|
76 |
+
|
77 |
+
"Copyright" also means copyright-like laws that apply to other kinds of
|
78 |
+
works, such as semiconductor masks.
|
79 |
+
|
80 |
+
"The Program" refers to any copyrightable work licensed under this
|
81 |
+
License. Each licensee is addressed as "you". "Licensees" and
|
82 |
+
"recipients" may be individuals or organizations.
|
83 |
+
|
84 |
+
To "modify" a work means to copy from or adapt all or part of the work
|
85 |
+
in a fashion requiring copyright permission, other than the making of an
|
86 |
+
exact copy. The resulting work is called a "modified version" of the
|
87 |
+
earlier work or a work "based on" the earlier work.
|
88 |
+
|
89 |
+
A "covered work" means either the unmodified Program or a work based
|
90 |
+
on the Program.
|
91 |
+
|
92 |
+
To "propagate" a work means to do anything with it that, without
|
93 |
+
permission, would make you directly or secondarily liable for
|
94 |
+
infringement under applicable copyright law, except executing it on a
|
95 |
+
computer or modifying a private copy. Propagation includes copying,
|
96 |
+
distribution (with or without modification), making available to the
|
97 |
+
public, and in some countries other activities as well.
|
98 |
+
|
99 |
+
To "convey" a work means any kind of propagation that enables other
|
100 |
+
parties to make or receive copies. Mere interaction with a user through
|
101 |
+
a computer network, with no transfer of a copy, is not conveying.
|
102 |
+
|
103 |
+
An interactive user interface displays "Appropriate Legal Notices"
|
104 |
+
to the extent that it includes a convenient and prominently visible
|
105 |
+
feature that (1) displays an appropriate copyright notice, and (2)
|
106 |
+
tells the user that there is no warranty for the work (except to the
|
107 |
+
extent that warranties are provided), that licensees may convey the
|
108 |
+
work under this License, and how to view a copy of this License. If
|
109 |
+
the interface presents a list of user commands or options, such as a
|
110 |
+
menu, a prominent item in the list meets this criterion.
|
111 |
+
|
112 |
+
1. Source Code.
|
113 |
+
|
114 |
+
The "source code" for a work means the preferred form of the work
|
115 |
+
for making modifications to it. "Object code" means any non-source
|
116 |
+
form of a work.
|
117 |
+
|
118 |
+
A "Standard Interface" means an interface that either is an official
|
119 |
+
standard defined by a recognized standards body, or, in the case of
|
120 |
+
interfaces specified for a particular programming language, one that
|
121 |
+
is widely used among developers working in that language.
|
122 |
+
|
123 |
+
The "System Libraries" of an executable work include anything, other
|
124 |
+
than the work as a whole, that (a) is included in the normal form of
|
125 |
+
packaging a Major Component, but which is not part of that Major
|
126 |
+
Component, and (b) serves only to enable use of the work with that
|
127 |
+
Major Component, or to implement a Standard Interface for which an
|
128 |
+
implementation is available to the public in source code form. A
|
129 |
+
"Major Component", in this context, means a major essential component
|
130 |
+
(kernel, window system, and so on) of the specific operating system
|
131 |
+
(if any) on which the executable work runs, or a compiler used to
|
132 |
+
produce the work, or an object code interpreter used to run it.
|
133 |
+
|
134 |
+
The "Corresponding Source" for a work in object code form means all
|
135 |
+
the source code needed to generate, install, and (for an executable
|
136 |
+
work) run the object code and to modify the work, including scripts to
|
137 |
+
control those activities. However, it does not include the work's
|
138 |
+
System Libraries, or general-purpose tools or generally available free
|
139 |
+
programs which are used unmodified in performing those activities but
|
140 |
+
which are not part of the work. For example, Corresponding Source
|
141 |
+
includes interface definition files associated with source files for
|
142 |
+
the work, and the source code for shared libraries and dynamically
|
143 |
+
linked subprograms that the work is specifically designed to require,
|
144 |
+
such as by intimate data communication or control flow between those
|
145 |
+
subprograms and other parts of the work.
|
146 |
+
|
147 |
+
The Corresponding Source need not include anything that users
|
148 |
+
can regenerate automatically from other parts of the Corresponding
|
149 |
+
Source.
|
150 |
+
|
151 |
+
The Corresponding Source for a work in source code form is that
|
152 |
+
same work.
|
153 |
+
|
154 |
+
2. Basic Permissions.
|
155 |
+
|
156 |
+
All rights granted under this License are granted for the term of
|
157 |
+
copyright on the Program, and are irrevocable provided the stated
|
158 |
+
conditions are met. This License explicitly affirms your unlimited
|
159 |
+
permission to run the unmodified Program. The output from running a
|
160 |
+
covered work is covered by this License only if the output, given its
|
161 |
+
content, constitutes a covered work. This License acknowledges your
|
162 |
+
rights of fair use or other equivalent, as provided by copyright law.
|
163 |
+
|
164 |
+
You may make, run and propagate covered works that you do not
|
165 |
+
convey, without conditions so long as your license otherwise remains
|
166 |
+
in force. You may convey covered works to others for the sole purpose
|
167 |
+
of having them make modifications exclusively for you, or provide you
|
168 |
+
with facilities for running those works, provided that you comply with
|
169 |
+
the terms of this License in conveying all material for which you do
|
170 |
+
not control copyright. Those thus making or running the covered works
|
171 |
+
for you must do so exclusively on your behalf, under your direction
|
172 |
+
and control, on terms that prohibit them from making any copies of
|
173 |
+
your copyrighted material outside their relationship with you.
|
174 |
+
|
175 |
+
Conveying under any other circumstances is permitted solely under
|
176 |
+
the conditions stated below. Sublicensing is not allowed; section 10
|
177 |
+
makes it unnecessary.
|
178 |
+
|
179 |
+
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
180 |
+
|
181 |
+
No covered work shall be deemed part of an effective technological
|
182 |
+
measure under any applicable law fulfilling obligations under article
|
183 |
+
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
184 |
+
similar laws prohibiting or restricting circumvention of such
|
185 |
+
measures.
|
186 |
+
|
187 |
+
When you convey a covered work, you waive any legal power to forbid
|
188 |
+
circumvention of technological measures to the extent such circumvention
|
189 |
+
is effected by exercising rights under this License with respect to
|
190 |
+
the covered work, and you disclaim any intention to limit operation or
|
191 |
+
modification of the work as a means of enforcing, against the work's
|
192 |
+
users, your or third parties' legal rights to forbid circumvention of
|
193 |
+
technological measures.
|
194 |
+
|
195 |
+
4. Conveying Verbatim Copies.
|
196 |
+
|
197 |
+
You may convey verbatim copies of the Program's source code as you
|
198 |
+
receive it, in any medium, provided that you conspicuously and
|
199 |
+
appropriately publish on each copy an appropriate copyright notice;
|
200 |
+
keep intact all notices stating that this License and any
|
201 |
+
non-permissive terms added in accord with section 7 apply to the code;
|
202 |
+
keep intact all notices of the absence of any warranty; and give all
|
203 |
+
recipients a copy of this License along with the Program.
|
204 |
+
|
205 |
+
You may charge any price or no price for each copy that you convey,
|
206 |
+
and you may offer support or warranty protection for a fee.
|
207 |
+
|
208 |
+
5. Conveying Modified Source Versions.
|
209 |
+
|
210 |
+
You may convey a work based on the Program, or the modifications to
|
211 |
+
produce it from the Program, in the form of source code under the
|
212 |
+
terms of section 4, provided that you also meet all of these conditions:
|
213 |
+
|
214 |
+
a) The work must carry prominent notices stating that you modified
|
215 |
+
it, and giving a relevant date.
|
216 |
+
|
217 |
+
b) The work must carry prominent notices stating that it is
|
218 |
+
released under this License and any conditions added under section
|
219 |
+
7. This requirement modifies the requirement in section 4 to
|
220 |
+
"keep intact all notices".
|
221 |
+
|
222 |
+
c) You must license the entire work, as a whole, under this
|
223 |
+
License to anyone who comes into possession of a copy. This
|
224 |
+
License will therefore apply, along with any applicable section 7
|
225 |
+
additional terms, to the whole of the work, and all its parts,
|
226 |
+
regardless of how they are packaged. This License gives no
|
227 |
+
permission to license the work in any other way, but it does not
|
228 |
+
invalidate such permission if you have separately received it.
|
229 |
+
|
230 |
+
d) If the work has interactive user interfaces, each must display
|
231 |
+
Appropriate Legal Notices; however, if the Program has interactive
|
232 |
+
interfaces that do not display Appropriate Legal Notices, your
|
233 |
+
work need not make them do so.
|
234 |
+
|
235 |
+
A compilation of a covered work with other separate and independent
|
236 |
+
works, which are not by their nature extensions of the covered work,
|
237 |
+
and which are not combined with it such as to form a larger program,
|
238 |
+
in or on a volume of a storage or distribution medium, is called an
|
239 |
+
"aggregate" if the compilation and its resulting copyright are not
|
240 |
+
used to limit the access or legal rights of the compilation's users
|
241 |
+
beyond what the individual works permit. Inclusion of a covered work
|
242 |
+
in an aggregate does not cause this License to apply to the other
|
243 |
+
parts of the aggregate.
|
244 |
+
|
245 |
+
6. Conveying Non-Source Forms.
|
246 |
+
|
247 |
+
You may convey a covered work in object code form under the terms
|
248 |
+
of sections 4 and 5, provided that you also convey the
|
249 |
+
machine-readable Corresponding Source under the terms of this License,
|
250 |
+
in one of these ways:
|
251 |
+
|
252 |
+
a) Convey the object code in, or embodied in, a physical product
|
253 |
+
(including a physical distribution medium), accompanied by the
|
254 |
+
Corresponding Source fixed on a durable physical medium
|
255 |
+
customarily used for software interchange.
|
256 |
+
|
257 |
+
b) Convey the object code in, or embodied in, a physical product
|
258 |
+
(including a physical distribution medium), accompanied by a
|
259 |
+
written offer, valid for at least three years and valid for as
|
260 |
+
long as you offer spare parts or customer support for that product
|
261 |
+
model, to give anyone who possesses the object code either (1) a
|
262 |
+
copy of the Corresponding Source for all the software in the
|
263 |
+
product that is covered by this License, on a durable physical
|
264 |
+
medium customarily used for software interchange, for a price no
|
265 |
+
more than your reasonable cost of physically performing this
|
266 |
+
conveying of source, or (2) access to copy the
|
267 |
+
Corresponding Source from a network server at no charge.
|
268 |
+
|
269 |
+
c) Convey individual copies of the object code with a copy of the
|
270 |
+
written offer to provide the Corresponding Source. This
|
271 |
+
alternative is allowed only occasionally and noncommercially, and
|
272 |
+
only if you received the object code with such an offer, in accord
|
273 |
+
with subsection 6b.
|
274 |
+
|
275 |
+
d) Convey the object code by offering access from a designated
|
276 |
+
place (gratis or for a charge), and offer equivalent access to the
|
277 |
+
Corresponding Source in the same way through the same place at no
|
278 |
+
further charge. You need not require recipients to copy the
|
279 |
+
Corresponding Source along with the object code. If the place to
|
280 |
+
copy the object code is a network server, the Corresponding Source
|
281 |
+
may be on a different server (operated by you or a third party)
|
282 |
+
that supports equivalent copying facilities, provided you maintain
|
283 |
+
clear directions next to the object code saying where to find the
|
284 |
+
Corresponding Source. Regardless of what server hosts the
|
285 |
+
Corresponding Source, you remain obligated to ensure that it is
|
286 |
+
available for as long as needed to satisfy these requirements.
|
287 |
+
|
288 |
+
e) Convey the object code using peer-to-peer transmission, provided
|
289 |
+
you inform other peers where the object code and Corresponding
|
290 |
+
Source of the work are being offered to the general public at no
|
291 |
+
charge under subsection 6d.
|
292 |
+
|
293 |
+
A separable portion of the object code, whose source code is excluded
|
294 |
+
from the Corresponding Source as a System Library, need not be
|
295 |
+
included in conveying the object code work.
|
296 |
+
|
297 |
+
A "User Product" is either (1) a "consumer product", which means any
|
298 |
+
tangible personal property which is normally used for personal, family,
|
299 |
+
or household purposes, or (2) anything designed or sold for incorporation
|
300 |
+
into a dwelling. In determining whether a product is a consumer product,
|
301 |
+
doubtful cases shall be resolved in favor of coverage. For a particular
|
302 |
+
product received by a particular user, "normally used" refers to a
|
303 |
+
typical or common use of that class of product, regardless of the status
|
304 |
+
of the particular user or of the way in which the particular user
|
305 |
+
actually uses, or expects or is expected to use, the product. A product
|
306 |
+
is a consumer product regardless of whether the product has substantial
|
307 |
+
commercial, industrial or non-consumer uses, unless such uses represent
|
308 |
+
the only significant mode of use of the product.
|
309 |
+
|
310 |
+
"Installation Information" for a User Product means any methods,
|
311 |
+
procedures, authorization keys, or other information required to install
|
312 |
+
and execute modified versions of a covered work in that User Product from
|
313 |
+
a modified version of its Corresponding Source. The information must
|
314 |
+
suffice to ensure that the continued functioning of the modified object
|
315 |
+
code is in no case prevented or interfered with solely because
|
316 |
+
modification has been made.
|
317 |
+
|
318 |
+
If you convey an object code work under this section in, or with, or
|
319 |
+
specifically for use in, a User Product, and the conveying occurs as
|
320 |
+
part of a transaction in which the right of possession and use of the
|
321 |
+
User Product is transferred to the recipient in perpetuity or for a
|
322 |
+
fixed term (regardless of how the transaction is characterized), the
|
323 |
+
Corresponding Source conveyed under this section must be accompanied
|
324 |
+
by the Installation Information. But this requirement does not apply
|
325 |
+
if neither you nor any third party retains the ability to install
|
326 |
+
modified object code on the User Product (for example, the work has
|
327 |
+
been installed in ROM).
|
328 |
+
|
329 |
+
The requirement to provide Installation Information does not include a
|
330 |
+
requirement to continue to provide support service, warranty, or updates
|
331 |
+
for a work that has been modified or installed by the recipient, or for
|
332 |
+
the User Product in which it has been modified or installed. Access to a
|
333 |
+
network may be denied when the modification itself materially and
|
334 |
+
adversely affects the operation of the network or violates the rules and
|
335 |
+
protocols for communication across the network.
|
336 |
+
|
337 |
+
Corresponding Source conveyed, and Installation Information provided,
|
338 |
+
in accord with this section must be in a format that is publicly
|
339 |
+
documented (and with an implementation available to the public in
|
340 |
+
source code form), and must require no special password or key for
|
341 |
+
unpacking, reading or copying.
|
342 |
+
|
343 |
+
7. Additional Terms.
|
344 |
+
|
345 |
+
"Additional permissions" are terms that supplement the terms of this
|
346 |
+
License by making exceptions from one or more of its conditions.
|
347 |
+
Additional permissions that are applicable to the entire Program shall
|
348 |
+
be treated as though they were included in this License, to the extent
|
349 |
+
that they are valid under applicable law. If additional permissions
|
350 |
+
apply only to part of the Program, that part may be used separately
|
351 |
+
under those permissions, but the entire Program remains governed by
|
352 |
+
this License without regard to the additional permissions.
|
353 |
+
|
354 |
+
When you convey a copy of a covered work, you may at your option
|
355 |
+
remove any additional permissions from that copy, or from any part of
|
356 |
+
it. (Additional permissions may be written to require their own
|
357 |
+
removal in certain cases when you modify the work.) You may place
|
358 |
+
additional permissions on material, added by you to a covered work,
|
359 |
+
for which you have or can give appropriate copyright permission.
|
360 |
+
|
361 |
+
Notwithstanding any other provision of this License, for material you
|
362 |
+
add to a covered work, you may (if authorized by the copyright holders of
|
363 |
+
that material) supplement the terms of this License with terms:
|
364 |
+
|
365 |
+
a) Disclaiming warranty or limiting liability differently from the
|
366 |
+
terms of sections 15 and 16 of this License; or
|
367 |
+
|
368 |
+
b) Requiring preservation of specified reasonable legal notices or
|
369 |
+
author attributions in that material or in the Appropriate Legal
|
370 |
+
Notices displayed by works containing it; or
|
371 |
+
|
372 |
+
c) Prohibiting misrepresentation of the origin of that material, or
|
373 |
+
requiring that modified versions of such material be marked in
|
374 |
+
reasonable ways as different from the original version; or
|
375 |
+
|
376 |
+
d) Limiting the use for publicity purposes of names of licensors or
|
377 |
+
authors of the material; or
|
378 |
+
|
379 |
+
e) Declining to grant rights under trademark law for use of some
|
380 |
+
trade names, trademarks, or service marks; or
|
381 |
+
|
382 |
+
f) Requiring indemnification of licensors and authors of that
|
383 |
+
material by anyone who conveys the material (or modified versions of
|
384 |
+
it) with contractual assumptions of liability to the recipient, for
|
385 |
+
any liability that these contractual assumptions directly impose on
|
386 |
+
those licensors and authors.
|
387 |
+
|
388 |
+
All other non-permissive additional terms are considered "further
|
389 |
+
restrictions" within the meaning of section 10. If the Program as you
|
390 |
+
received it, or any part of it, contains a notice stating that it is
|
391 |
+
governed by this License along with a term that is a further
|
392 |
+
restriction, you may remove that term. If a license document contains
|
393 |
+
a further restriction but permits relicensing or conveying under this
|
394 |
+
License, you may add to a covered work material governed by the terms
|
395 |
+
of that license document, provided that the further restriction does
|
396 |
+
not survive such relicensing or conveying.
|
397 |
+
|
398 |
+
If you add terms to a covered work in accord with this section, you
|
399 |
+
must place, in the relevant source files, a statement of the
|
400 |
+
additional terms that apply to those files, or a notice indicating
|
401 |
+
where to find the applicable terms.
|
402 |
+
|
403 |
+
Additional terms, permissive or non-permissive, may be stated in the
|
404 |
+
form of a separately written license, or stated as exceptions;
|
405 |
+
the above requirements apply either way.
|
406 |
+
|
407 |
+
8. Termination.
|
408 |
+
|
409 |
+
You may not propagate or modify a covered work except as expressly
|
410 |
+
provided under this License. Any attempt otherwise to propagate or
|
411 |
+
modify it is void, and will automatically terminate your rights under
|
412 |
+
this License (including any patent licenses granted under the third
|
413 |
+
paragraph of section 11).
|
414 |
+
|
415 |
+
However, if you cease all violation of this License, then your
|
416 |
+
license from a particular copyright holder is reinstated (a)
|
417 |
+
provisionally, unless and until the copyright holder explicitly and
|
418 |
+
finally terminates your license, and (b) permanently, if the copyright
|
419 |
+
holder fails to notify you of the violation by some reasonable means
|
420 |
+
prior to 60 days after the cessation.
|
421 |
+
|
422 |
+
Moreover, your license from a particular copyright holder is
|
423 |
+
reinstated permanently if the copyright holder notifies you of the
|
424 |
+
violation by some reasonable means, this is the first time you have
|
425 |
+
received notice of violation of this License (for any work) from that
|
426 |
+
copyright holder, and you cure the violation prior to 30 days after
|
427 |
+
your receipt of the notice.
|
428 |
+
|
429 |
+
Termination of your rights under this section does not terminate the
|
430 |
+
licenses of parties who have received copies or rights from you under
|
431 |
+
this License. If your rights have been terminated and not permanently
|
432 |
+
reinstated, you do not qualify to receive new licenses for the same
|
433 |
+
material under section 10.
|
434 |
+
|
435 |
+
9. Acceptance Not Required for Having Copies.
|
436 |
+
|
437 |
+
You are not required to accept this License in order to receive or
|
438 |
+
run a copy of the Program. Ancillary propagation of a covered work
|
439 |
+
occurring solely as a consequence of using peer-to-peer transmission
|
440 |
+
to receive a copy likewise does not require acceptance. However,
|
441 |
+
nothing other than this License grants you permission to propagate or
|
442 |
+
modify any covered work. These actions infringe copyright if you do
|
443 |
+
not accept this License. Therefore, by modifying or propagating a
|
444 |
+
covered work, you indicate your acceptance of this License to do so.
|
445 |
+
|
446 |
+
10. Automatic Licensing of Downstream Recipients.
|
447 |
+
|
448 |
+
Each time you convey a covered work, the recipient automatically
|
449 |
+
receives a license from the original licensors, to run, modify and
|
450 |
+
propagate that work, subject to this License. You are not responsible
|
451 |
+
for enforcing compliance by third parties with this License.
|
452 |
+
|
453 |
+
An "entity transaction" is a transaction transferring control of an
|
454 |
+
organization, or substantially all assets of one, or subdividing an
|
455 |
+
organization, or merging organizations. If propagation of a covered
|
456 |
+
work results from an entity transaction, each party to that
|
457 |
+
transaction who receives a copy of the work also receives whatever
|
458 |
+
licenses to the work the party's predecessor in interest had or could
|
459 |
+
give under the previous paragraph, plus a right to possession of the
|
460 |
+
Corresponding Source of the work from the predecessor in interest, if
|
461 |
+
the predecessor has it or can get it with reasonable efforts.
|
462 |
+
|
463 |
+
You may not impose any further restrictions on the exercise of the
|
464 |
+
rights granted or affirmed under this License. For example, you may
|
465 |
+
not impose a license fee, royalty, or other charge for exercise of
|
466 |
+
rights granted under this License, and you may not initiate litigation
|
467 |
+
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
468 |
+
any patent claim is infringed by making, using, selling, offering for
|
469 |
+
sale, or importing the Program or any portion of it.
|
470 |
+
|
471 |
+
11. Patents.
|
472 |
+
|
473 |
+
A "contributor" is a copyright holder who authorizes use under this
|
474 |
+
License of the Program or a work on which the Program is based. The
|
475 |
+
work thus licensed is called the contributor's "contributor version".
|
476 |
+
|
477 |
+
A contributor's "essential patent claims" are all patent claims
|
478 |
+
owned or controlled by the contributor, whether already acquired or
|
479 |
+
hereafter acquired, that would be infringed by some manner, permitted
|
480 |
+
by this License, of making, using, or selling its contributor version,
|
481 |
+
but do not include claims that would be infringed only as a
|
482 |
+
consequence of further modification of the contributor version. For
|
483 |
+
purposes of this definition, "control" includes the right to grant
|
484 |
+
patent sublicenses in a manner consistent with the requirements of
|
485 |
+
this License.
|
486 |
+
|
487 |
+
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
488 |
+
patent license under the contributor's essential patent claims, to
|
489 |
+
make, use, sell, offer for sale, import and otherwise run, modify and
|
490 |
+
propagate the contents of its contributor version.
|
491 |
+
|
492 |
+
In the following three paragraphs, a "patent license" is any express
|
493 |
+
agreement or commitment, however denominated, not to enforce a patent
|
494 |
+
(such as an express permission to practice a patent or covenant not to
|
495 |
+
sue for patent infringement). To "grant" such a patent license to a
|
496 |
+
party means to make such an agreement or commitment not to enforce a
|
497 |
+
patent against the party.
|
498 |
+
|
499 |
+
If you convey a covered work, knowingly relying on a patent license,
|
500 |
+
and the Corresponding Source of the work is not available for anyone
|
501 |
+
to copy, free of charge and under the terms of this License, through a
|
502 |
+
publicly available network server or other readily accessible means,
|
503 |
+
then you must either (1) cause the Corresponding Source to be so
|
504 |
+
available, or (2) arrange to deprive yourself of the benefit of the
|
505 |
+
patent license for this particular work, or (3) arrange, in a manner
|
506 |
+
consistent with the requirements of this License, to extend the patent
|
507 |
+
license to downstream recipients. "Knowingly relying" means you have
|
508 |
+
actual knowledge that, but for the patent license, your conveying the
|
509 |
+
covered work in a country, or your recipient's use of the covered work
|
510 |
+
in a country, would infringe one or more identifiable patents in that
|
511 |
+
country that you have reason to believe are valid.
|
512 |
+
|
513 |
+
If, pursuant to or in connection with a single transaction or
|
514 |
+
arrangement, you convey, or propagate by procuring conveyance of, a
|
515 |
+
covered work, and grant a patent license to some of the parties
|
516 |
+
receiving the covered work authorizing them to use, propagate, modify
|
517 |
+
or convey a specific copy of the covered work, then the patent license
|
518 |
+
you grant is automatically extended to all recipients of the covered
|
519 |
+
work and works based on it.
|
520 |
+
|
521 |
+
A patent license is "discriminatory" if it does not include within
|
522 |
+
the scope of its coverage, prohibits the exercise of, or is
|
523 |
+
conditioned on the non-exercise of one or more of the rights that are
|
524 |
+
specifically granted under this License. You may not convey a covered
|
525 |
+
work if you are a party to an arrangement with a third party that is
|
526 |
+
in the business of distributing software, under which you make payment
|
527 |
+
to the third party based on the extent of your activity of conveying
|
528 |
+
the work, and under which the third party grants, to any of the
|
529 |
+
parties who would receive the covered work from you, a discriminatory
|
530 |
+
patent license (a) in connection with copies of the covered work
|
531 |
+
conveyed by you (or copies made from those copies), or (b) primarily
|
532 |
+
for and in connection with specific products or compilations that
|
533 |
+
contain the covered work, unless you entered into that arrangement,
|
534 |
+
or that patent license was granted, prior to 28 March 2007.
|
535 |
+
|
536 |
+
Nothing in this License shall be construed as excluding or limiting
|
537 |
+
any implied license or other defenses to infringement that may
|
538 |
+
otherwise be available to you under applicable patent law.
|
539 |
+
|
540 |
+
12. No Surrender of Others' Freedom.
|
541 |
+
|
542 |
+
If conditions are imposed on you (whether by court order, agreement or
|
543 |
+
otherwise) that contradict the conditions of this License, they do not
|
544 |
+
excuse you from the conditions of this License. If you cannot convey a
|
545 |
+
covered work so as to satisfy simultaneously your obligations under this
|
546 |
+
License and any other pertinent obligations, then as a consequence you may
|
547 |
+
not convey it at all. For example, if you agree to terms that obligate you
|
548 |
+
to collect a royalty for further conveying from those to whom you convey
|
549 |
+
the Program, the only way you could satisfy both those terms and this
|
550 |
+
License would be to refrain entirely from conveying the Program.
|
551 |
+
|
552 |
+
13. Use with the GNU Affero General Public License.
|
553 |
+
|
554 |
+
Notwithstanding any other provision of this License, you have
|
555 |
+
permission to link or combine any covered work with a work licensed
|
556 |
+
under version 3 of the GNU Affero General Public License into a single
|
557 |
+
combined work, and to convey the resulting work. The terms of this
|
558 |
+
License will continue to apply to the part which is the covered work,
|
559 |
+
but the special requirements of the GNU Affero General Public License,
|
560 |
+
section 13, concerning interaction through a network will apply to the
|
561 |
+
combination as such.
|
562 |
+
|
563 |
+
14. Revised Versions of this License.
|
564 |
+
|
565 |
+
The Free Software Foundation may publish revised and/or new versions of
|
566 |
+
the GNU General Public License from time to time. Such new versions will
|
567 |
+
be similar in spirit to the present version, but may differ in detail to
|
568 |
+
address new problems or concerns.
|
569 |
+
|
570 |
+
Each version is given a distinguishing version number. If the
|
571 |
+
Program specifies that a certain numbered version of the GNU General
|
572 |
+
Public License "or any later version" applies to it, you have the
|
573 |
+
option of following the terms and conditions either of that numbered
|
574 |
+
version or of any later version published by the Free Software
|
575 |
+
Foundation. If the Program does not specify a version number of the
|
576 |
+
GNU General Public License, you may choose any version ever published
|
577 |
+
by the Free Software Foundation.
|
578 |
+
|
579 |
+
If the Program specifies that a proxy can decide which future
|
580 |
+
versions of the GNU General Public License can be used, that proxy's
|
581 |
+
public statement of acceptance of a version permanently authorizes you
|
582 |
+
to choose that version for the Program.
|
583 |
+
|
584 |
+
Later license versions may give you additional or different
|
585 |
+
permissions. However, no additional obligations are imposed on any
|
586 |
+
author or copyright holder as a result of your choosing to follow a
|
587 |
+
later version.
|
588 |
+
|
589 |
+
15. Disclaimer of Warranty.
|
590 |
+
|
591 |
+
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
592 |
+
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
593 |
+
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
594 |
+
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
595 |
+
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
596 |
+
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
597 |
+
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
598 |
+
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
599 |
+
|
600 |
+
16. Limitation of Liability.
|
601 |
+
|
602 |
+
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
603 |
+
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
604 |
+
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
605 |
+
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
606 |
+
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
607 |
+
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
608 |
+
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
609 |
+
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
610 |
+
SUCH DAMAGES.
|
611 |
+
|
612 |
+
17. Interpretation of Sections 15 and 16.
|
613 |
+
|
614 |
+
If the disclaimer of warranty and limitation of liability provided
|
615 |
+
above cannot be given local legal effect according to their terms,
|
616 |
+
reviewing courts shall apply local law that most closely approximates
|
617 |
+
an absolute waiver of all civil liability in connection with the
|
618 |
+
Program, unless a warranty or assumption of liability accompanies a
|
619 |
+
copy of the Program in return for a fee.
|
620 |
+
|
621 |
+
END OF TERMS AND CONDITIONS
|
622 |
+
|
623 |
+
How to Apply These Terms to Your New Programs
|
624 |
+
|
625 |
+
If you develop a new program, and you want it to be of the greatest
|
626 |
+
possible use to the public, the best way to achieve this is to make it
|
627 |
+
free software which everyone can redistribute and change under these terms.
|
628 |
+
|
629 |
+
To do so, attach the following notices to the program. It is safest
|
630 |
+
to attach them to the start of each source file to most effectively
|
631 |
+
state the exclusion of warranty; and each file should have at least
|
632 |
+
the "copyright" line and a pointer to where the full notice is found.
|
633 |
+
|
634 |
+
{one line to give the program's name and a brief idea of what it does.}
|
635 |
+
Copyright (C) {year} {name of author}
|
636 |
+
|
637 |
+
This program is free software: you can redistribute it and/or modify
|
638 |
+
it under the terms of the GNU General Public License as published by
|
639 |
+
the Free Software Foundation, either version 3 of the License, or
|
640 |
+
(at your option) any later version.
|
641 |
+
|
642 |
+
This program is distributed in the hope that it will be useful,
|
643 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
644 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
645 |
+
GNU General Public License for more details.
|
646 |
+
|
647 |
+
You should have received a copy of the GNU General Public License
|
648 |
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
649 |
+
|
650 |
+
Also add information on how to contact you by electronic and paper mail.
|
651 |
+
|
652 |
+
If the program does terminal interaction, make it output a short
|
653 |
+
notice like this when it starts in an interactive mode:
|
654 |
+
|
655 |
+
{project} Copyright (C) {year} {fullname}
|
656 |
+
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
657 |
+
This is free software, and you are welcome to redistribute it
|
658 |
+
under certain conditions; type `show c' for details.
|
659 |
+
|
660 |
+
The hypothetical commands `show w' and `show c' should show the appropriate
|
661 |
+
parts of the General Public License. Of course, your program's commands
|
662 |
+
might be different; for a GUI interface, you would use an "about box".
|
663 |
+
|
664 |
+
You should also get your employer (if you work as a programmer) or school,
|
665 |
+
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
666 |
+
For more information on this, and how to apply and follow the GNU GPL, see
|
667 |
+
<http://www.gnu.org/licenses/>.
|
668 |
+
|
669 |
+
The GNU General Public License does not permit incorporating your program
|
670 |
+
into proprietary programs. If your program is a subroutine library, you
|
671 |
+
may consider it more useful to permit linking proprietary applications with
|
672 |
+
the library. If this is what you want to do, use the GNU Lesser General
|
673 |
+
Public License instead of this License. But first, please read
|
674 |
+
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
README.md
ADDED
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# WebP Express
|
2 |
+
|
3 |
+
Serve autogenerated WebP images instead of jpeg/png to browsers that supports WebP. Works on anything (media library, galleries, theme images etc).
|
4 |
+
|
5 |
+
## Description
|
6 |
+
|
7 |
+
This plugin let's you take advantage of the WebP image format with only a little effort. Install, configure, test, forget - and enjoy the increased performance of your website.
|
8 |
+
|
9 |
+
The plugin works by .htaccess magic coupled with an image converter. Basically, jpegs and pngs are routed to the image converter, unless the image converter has already converted the image. In that case, it is routed directly to the converted image. The images are saved in a subfolder to the "uploads" folder, preserving the same structure as the originals. In order to allow caching on CDN, the .htaccess rules add a "Vary" HTTP header when serving the WebP images.
|
10 |
+
|
11 |
+
The approach has the benefit that is works regardless of how an image found its way into your site. The plugin does not need to hook into Media Library events, Gallery events etc, because it does not need to maintain a complete collection of converted images. It makes it so much simpler -- and lighter.
|
12 |
+
|
13 |
+
*Note:*
|
14 |
+
The rules created in .htaccess are sensitive to the location of your image folder and the location of wordpress. If you at some point change one of these, the rules will have to be updated. .htaccess rules are updated whenever you change a setting (all configuration is actually stored in .htaccess, which allows the converter to run faster, than if it had the overhead of bootstrapping Wordpress)
|
15 |
+
|
16 |
+
*Note:*
|
17 |
+
Do not simply remove the plugin without deactivating it first. Deactivation takes care of removing the rules in the .htaccess file. With the rules there, but converter gone, your Google Chrome visitors will not see any jpeg images.
|
18 |
+
|
19 |
+
*Note:*
|
20 |
+
The plugin has not been tested in multisite configurations. It's on the roadmap!
|
21 |
+
|
22 |
+
|
23 |
+
## Installation
|
24 |
+
|
25 |
+
1. Upload the plugin files to the `/wp-content/plugins/webp-express` directory, or install the plugin through the WordPress plugins screen directly.
|
26 |
+
2. Activate the plugin through the 'Plugins' screen in WordPress
|
27 |
+
3. Configure it (the plugin doesn't do anything until configured)
|
28 |
+
4. Verify that it works
|
29 |
+
|
30 |
+
You configure the plugin in *Settings > WebP Express*.
|
31 |
+
|
32 |
+
The *Image types to convert* option is initially set to "Do not convert any images!". This allows you to test that there is a working converter, before redirecting images to the converter.
|
33 |
+
|
34 |
+
WebPExpress uses [WebPConvert](https://github.com/rosell-dk/webp-convert) to convert images. This is how WebPConvert describes itself:
|
35 |
+
|
36 |
+
*The current state of WebP conversion in PHP is this: There are several ways to do it, but they all require something of the server setup. What works on one shared host might not work on another. WebPConvert combines these methods by iterating over them (optionally in the desired order) until one of them is successful - or all of them fail.*
|
37 |
+
|
38 |
+
These different converting methods are called *converters*.
|
39 |
+
|
40 |
+
The best converter is *cwebp*. So the first thing you should do is test whether the cwebp converter is working. Simply click "test" next to the converter. If it doesn't work, you can disable that converter (or try to make it work, by changing the server setup).
|
41 |
+
The next converter to try is *wpc*, which is equally good as cwebp in terms of quality / filesize ratio, but which is slower. wpc is an open source cloud service, which you will have to install on some other server. If this is too much work, continue to the next converter. In the converter settings, you can read about the individual converters. You can also head to the WebPConvert readme for more information.
|
42 |
+
|
43 |
+
Once, you have a converter, that works, when you click the "test"-button, you are ready to test the whole stack, and the rewrite rules. To do this, first make sure to select something other than "Do not convert any images!" in *Image types to convert*. Next, click "Save settings". This will save settings, as well as update the .htaccess.
|
44 |
+
|
45 |
+
If you are working in a browser that supports webp (ie Google Chrome), you will see a link "Convert test image (show debug)" just above the "Save settings" button. Click that to test if it works. The screen should show a textual report of the conversion process. If it shows an image, it means that the .htaccess redirection isn't working. It may be that your server just needs some time. Some servers has set up caching.
|
46 |
+
|
47 |
+
Note that the plugin does not change any HTML. In the HTML the image src is still set to ie "example.jpg". To verify that the plugin is working (without clicking the test button), do the following:
|
48 |
+
|
49 |
+
- Open the page in Google Chrome
|
50 |
+
- Right-click the page and choose "Inspect"
|
51 |
+
- Click the "Network" tab
|
52 |
+
- Reload the page
|
53 |
+
- Find a jpeg or png image in the list. In the "type" column, it should say "webp"
|
54 |
+
|
55 |
+
You can also append `?debug` after any image url, in order to run a conversion, and see the conversion report. Btw: If you append `?reconvert` after an image url, you will force a reconversion of the image.
|
56 |
+
|
57 |
+
|
58 |
+
## Limitations
|
59 |
+
|
60 |
+
* The plugin does not work on Microsoft IIS server
|
61 |
+
* The plugin has not been tested with multisite installation (it is on the roadmap!).
|
62 |
+
* The plugin has only been tested in Wordpress 4.7.5 and above, but I expect it to work in other versions.
|
63 |
+
* The plugin has not been tested in all possible Wordpress configurations. It has been tested in the following configurations: root install, subdir install, and subdir install with redirect from root (described as method 1 (here)[https://codex.wordpress.org/Giving_WordPress_Its_Own_Directory]).
|
64 |
+
* There might be compatability issues with other plugins. For example .htaccess rules from other plugins might interfere.
|
65 |
+
|
66 |
+
## Known compatability issues
|
67 |
+
* W3TotalCache: When CDN is enabled, W3TotalCache creates some .htaccess rules which interferes when they appear before the rules created by this plugin. You can move them by manually editing the .htaccess file
|
68 |
+
|
69 |
+
## Frequently Asked Questions
|
70 |
+
|
71 |
+
### How do I set the WebP quality?
|
72 |
+
You don't. The plugin will try to detect the quality of the source file, and use same quality as that. You do however have an option to select a maximum quality - usefull, because there is seldom any need for a quality above 85 on ordinary web content. In case quality of the source file cannot be determined (that feature requires that Imagick or GraphicsMagick is installed), it will be set to 80.
|
73 |
+
|
74 |
+
### How do I make this work with a CDN?
|
75 |
+
Chances are that the default setting of your CDN is not to forward any headers to your origin server. But the plugin needs the "Accept" header, because this is where the information is whether the browser accepts webp images or not. You will therefore have to make sure to configure your CDN to forward the "Accept" header.
|
76 |
+
|
77 |
+
The plugin takes care of setting the "Vary" HTTP header to "Accept" when routing WebP images. When the CDN sees this, it knows that the response varies, depending on the "Accept" header. The CDN is thus instructed not to cache the response on URL only, but also on the "Accept" header. This means that it will store an image for every accept header it meets. Luckily, there are (not that many variants for images)[https://developer.mozilla.org/en-US/docs/Web/HTTP/Content_negotiation/List_of_default_Accept_values#Values_for_an_image], so it is not an issue.
|
78 |
+
|
79 |
+
### How do I donate?
|
80 |
+
Putting this question in the "frequently" asked questions section is of course some mixture of humour, sarcasm and wishful thinking. In case there really is someone out there wanting to donate, you can simply write to me, and we can arrange. My contact information is available here https://www.bitwise-it.dk/contact. I have paypal and of course an ordinary bank account.
|
81 |
+
|
82 |
+
# Roadmap
|
83 |
+
|
84 |
+
* Test on multisite
|
85 |
+
* Display whether the server is able to detect quality of jpegs or not
|
86 |
+
* Make the fallback quality configurable (the quality to use, when quality of source file cannot be determined)
|
README.txt
ADDED
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
=== WebP Express ===
|
2 |
+
Contributors: rosell.dk
|
3 |
+
Donate link: https://www.bitwise-it.dk/contact
|
4 |
+
Tags: webp, images, performance
|
5 |
+
Requires at least: 4.7.5
|
6 |
+
Tested up to: 4.9.7
|
7 |
+
Stable tag: 0.2
|
8 |
+
Requires PHP: 5.5
|
9 |
+
License: GPLv3
|
10 |
+
License URI: https://www.gnu.org/licenses/gpl-3.0.html
|
11 |
+
|
12 |
+
Serve autogenerated WebP images instead of jpeg/png to browsers that supports WebP. Works on all images (media library, galleries, theme images, ...).
|
13 |
+
|
14 |
+
== Description ==
|
15 |
+
|
16 |
+
This plugin let's you take advantage of the WebP image format with only a little effort. Install, configure, test, forget - and enjoy the increased performance of your website.
|
17 |
+
|
18 |
+
The plugin works by .htaccess magic coupled with an image converter. Basically, jpegs and pngs are routed to the image converter, unless the image converter has already converted the image. In that case, it is routed directly to the converted image. The images are saved in a subfolder to the "uploads" folder, preserving the same structure as the originals. In order to allow caching on CDN, the .htaccess rules add a "Vary" HTTP header when serving the WebP images.
|
19 |
+
|
20 |
+
The approach has the benefit that is works regardless of how an image found its way into your site. The plugin does not need to hook into Media Library events, Gallery events etc, because it does not need to maintain a complete collection of converted images. It makes it so much simpler -- and lighter.
|
21 |
+
|
22 |
+
Note: The rules created in .htaccess are sensitive to the location of your image folder and the location of wordpress. If you at some point change one of these, the rules will have to be updated. .htaccess rules are updated whenever you change a setting (all configuration is actually stored in .htaccess, which allows the converter to run faster, than if it had the overhead of bootstrapping Wordpress)
|
23 |
+
|
24 |
+
Note: Do not simply remove the plugin without deactivating it first. Deactivation takes care of removing the rules in the .htaccess file. With the rules there, but converter gone, your Google Chrome visitors will not see any jpeg images.
|
25 |
+
|
26 |
+
Note: The plugin has not been tested in multisite configurations. It's on the roadmap!
|
27 |
+
|
28 |
+
|
29 |
+
== Installation ==
|
30 |
+
|
31 |
+
1. Upload the plugin files to the `/wp-content/plugins/webp-express` directory, or install the plugin through the WordPress plugins screen directly.
|
32 |
+
2. Activate the plugin through the 'Plugins' screen in WordPress
|
33 |
+
3. Configure it (the plugin doesn't do anything until configured)
|
34 |
+
4. Verify that it works
|
35 |
+
|
36 |
+
You configure the plugin in Settings > WebP Express.
|
37 |
+
|
38 |
+
The "Image types to convert" option is initially set to "Do not convert any images!". This allows you to test that there is a working converter, before redirecting images to the converter.
|
39 |
+
|
40 |
+
WebPExpress uses WebPConvert (https://github.com/rosell-dk/webp-convert) to convert images. This is how WebPConvert describes itself:
|
41 |
+
|
42 |
+
"The current state of WebP conversion in PHP is this: There are several ways to do it, but they all require something of the server setup. What works on one shared host might not work on another. WebPConvert combines these methods by iterating over them (optionally in the desired order) until one of them is successful - or all of them fail."
|
43 |
+
|
44 |
+
WebPConvert calls these different converting methods "converters".
|
45 |
+
|
46 |
+
The best converter is cwebp. So the first thing you should do is test whether the cwebp converter is working. Simply click "test" next to the converter. If it doesn't work, you can disable that converter (or try to make it work, by changing the server setup).
|
47 |
+
|
48 |
+
The next converter to try is wpc, which is equally good as cwebp in terms of quality / filesize ratio, but which is slower. wpc is an open source cloud service, which you will have to install on some other server. It is btw on the roadmap to have this plugin provide the same service. If installing wpc too much work, continue to the next converter. I will not go through all of them here; you can learn more by clicking on the "configure" button on a converter. You can also head to the WebPConvert project for more information.
|
49 |
+
|
50 |
+
Once, you have a converter, that works, when you click the "test"-button, you are ready to test the whole stack, and the rewrite rules. To do this, first make sure to select something other than "Do not convert any images!" in "Image types to convert". Next, click "Save settings". This will save settings, as well as update the .htaccess.
|
51 |
+
|
52 |
+
If you are working in a browser that supports webp (ie Google Chrome), you will see a link "Convert test image (show debug)" just above the "Save settings" button. Click that to test if it works. The screen should show a textual report of the conversion process. If it shows an image, it means that the .htaccess redirection isn't working. It may be that your server just needs some time. Some servers has set up caching.
|
53 |
+
|
54 |
+
Note that the plugin does not change any HTML. In the HTML the image src is still set to ie "example.jpg". To verify that the plugin is working (without clicking the test button), do the following:
|
55 |
+
|
56 |
+
- Open the page in Google Chrome
|
57 |
+
- Right-click the page and choose "Inspect"
|
58 |
+
- Click the "Network" tab
|
59 |
+
- Reload the page
|
60 |
+
- Find a jpeg or png image in the list. In the "type" column, it should say "webp"
|
61 |
+
|
62 |
+
You can also append ?debug after any image url, in order to run a conversion, and see the conversion report.
|
63 |
+
Btw: If you append ?reconvert after an image url, you will force a reconversion of the image.
|
64 |
+
|
65 |
+
== Screenshots ==
|
66 |
+
|
67 |
+
|
68 |
+
== Limitations ==
|
69 |
+
|
70 |
+
* The plugin does not work on Microsoft IIS server
|
71 |
+
* The plugin has not been tested with multisite installation (it is on the roadmap!).
|
72 |
+
* The plugin has only been tested in Wordpress 4.7.5 and above, but I expect it to work in other versions.
|
73 |
+
* The plugin has not been tested in all possible Wordpress configurations. It has been tested in the following configurations: root install, subdir install, and subdir install with redirect from root (described as method 1 (here)[https://codex.wordpress.org/Giving_WordPress_Its_Own_Directory]).
|
74 |
+
* There might be compatability issues with other plugins. For example .htaccess rules from other plugins might interfere.
|
75 |
+
|
76 |
+
== Frequently Asked Questions ==
|
77 |
+
|
78 |
+
= How do I set the WebP quality? =
|
79 |
+
You don't. The plugin will try to detect the quality of the source file, and use same quality as that. You do however have an option to select a maximum quality - usefull, because there is seldom any need for a quality above 85 on ordinary web content. In case quality of the source file cannot be determined (that feature requires that Imagick or GraphicsMagick is installed), it will be set to 80.
|
80 |
+
|
81 |
+
= How do I make this work with a CDN? =
|
82 |
+
Chances are that the default setting of your CDN is not to forward any headers to your origin server. But the plugin needs the "Accept" header, because this is where the information is whether the browser accepts webp images or not. You will therefore have to make sure to configure your CDN to forward the "Accept" header.
|
83 |
+
|
84 |
+
The plugin takes care of setting the "Vary" HTTP header to "Accept" when routing WebP images. When the CDN sees this, it knows that the response varies, depending on the "Accept" header. The CDN is thus instructed not to cache the response on URL only, but also on the "Accept" header. This means that it will store an image for every accept header it meets. Luckily, there are not that many variants for images:
|
85 |
+
https://developer.mozilla.org/en-US/docs/Web/HTTP/Content_negotiation/List_of_default_Accept_values#Values_for_an_image
|
86 |
+
- so it is not an issue.
|
87 |
+
|
88 |
+
= How do I donate? =
|
89 |
+
Putting this question in the "frequently" asked questions section is of course some mixture of humour, sarcasm and wishful thinking. In case there really is someone out there wanting to donate, you can simply write to me, and we can arrange. My contact information is available here https://www.bitwise-it.dk/contact. I have paypal and of course an ordinary bank account.
|
90 |
+
|
91 |
+
== Screenshots ==
|
92 |
+
|
93 |
+
1. WebP Express settings
|
94 |
+
|
95 |
+
== Changelog ==
|
96 |
+
|
97 |
+
= 0.2 =
|
98 |
+
* Plugin created. Enjoy!
|
99 |
+
|
100 |
+
== Roadmap ==
|
101 |
+
|
102 |
+
* Optionally provide conversion service for other sites
|
103 |
+
* Test on multisite
|
104 |
+
* Display whether the server is able to detect quality of jpegs or not
|
105 |
+
* Make the fallback quality configurable (the quality to use, when quality of source file cannot be determined)
|
assets/banner-772x250.jpg
ADDED
Binary file
|
assets/icon-128x128.png
ADDED
Binary file
|
assets/icon-256x256.png
ADDED
Binary file
|
assets/icon.svg
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
2 |
+
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
3 |
+
|
4 |
+
<svg
|
5 |
+
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
6 |
+
xmlns:cc="http://creativecommons.org/ns#"
|
7 |
+
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
8 |
+
xmlns:svg="http://www.w3.org/2000/svg"
|
9 |
+
xmlns="http://www.w3.org/2000/svg"
|
10 |
+
version="1.1"
|
11 |
+
width="150"
|
12 |
+
height="150"
|
13 |
+
id="svg3062"
|
14 |
+
xml:space="preserve"><metadata
|
15 |
+
id="metadata3068"><rdf:RDF><cc:Work
|
16 |
+
rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
|
17 |
+
rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title></dc:title></cc:Work></rdf:RDF></metadata><defs
|
18 |
+
id="defs3066" /><g
|
19 |
+
transform="matrix(1.25,0,0,-1.25,0,150)"
|
20 |
+
id="g3070"><g
|
21 |
+
id="g3072"><path
|
22 |
+
d="M 0,0 120,0 120,120 0,120 0,0 z"
|
23 |
+
id="path3074"
|
24 |
+
style="fill:#154889;fill-opacity:1;fill-rule:nonzero;stroke:none" /><path
|
25 |
+
d="m 39.695,22.855 -31.695,0 23.77,74.29 10.648,0 -2.723,-74.29 z m 8.914,0 -2.722,74.29 10.648,0 8.008,-25.036 c 6.035,6.606 13.895,11.528 22.473,14.075 l -9.563,8.027 c -0.875,0.773 -0.535,2.473 0.574,2.844 0.172,0.058 0.352,0.09 0.536,0.09 l 31.761,0 c 1.102,0 1.969,-1.313 1.547,-2.325 L 99.566,65.535 c -0.453,-1.078 -2.171,-1.297 -2.875,-0.363 -0.113,0.144 -0.199,0.305 -0.253,0.476 l -4.727,14.106 c -4.535,-1.649 -8.715,-4.25 -11.859,-7.379 -3.145,-3.129 -5.243,-6.773 -5.95,-10.34 l -0.05,-0.277 C 72.445,54.531 73.543,43.988 76.738,34 l 3.567,-11.145 -31.696,0 z"
|
26 |
+
id="path3076"
|
27 |
+
style="fill:#ffffff;fill-opacity:1;fill-rule:evenodd;stroke:none" /></g></g></svg>
|
assets/screenshot-1.png
ADDED
Binary file
|
convert.php
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
//require 'webp-on-demand/vendor/autoload.php';
|
4 |
+
|
5 |
+
|
6 |
+
//require 'vendor/webp-convert-and-serve/autoload.php';
|
7 |
+
require 'vendor/webp-on-demand/autoload.php';
|
8 |
+
|
9 |
+
//echo '<br>done';
|
10 |
+
|
11 |
+
//require '../webp-convert/WebPConvert.php';
|
12 |
+
|
13 |
+
|
14 |
+
/*use WebPConvert\WebPConvert;
|
15 |
+
|
16 |
+
$source = __DIR__ . '/test/test.jpg';
|
17 |
+
$destination = __DIR__ . '/test/test.jpg.webp';
|
18 |
+
|
19 |
+
// .. fire up WebP conversion
|
20 |
+
$success = WebPConvert::convert($source, $destination, array(
|
21 |
+
'quality' => 90,
|
22 |
+
// more options available!
|
23 |
+
));
|
24 |
+
|
25 |
+
|
26 |
+
//$status = WebPOnDemand::serve(__DIR__);
|
27 |
+
|
28 |
+
//echo 'hi';
|
29 |
+
*/
|
30 |
+
|
31 |
+
|
32 |
+
use WebPOnDemand\WebPOnDemand;
|
33 |
+
|
34 |
+
$status = WebPOnDemand::serve(__DIR__);
|
35 |
+
if ($status < 0) {
|
36 |
+
// Conversion failed.
|
37 |
+
// you could message your application about the problem here...
|
38 |
+
}
|
css/webp-express-options-page.css
ADDED
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
input[name=webp_express_converters] {
|
2 |
+
display: none;
|
3 |
+
width: 100%;
|
4 |
+
}
|
5 |
+
|
6 |
+
/* remove the padding on the row with the hidden "webp_express_converters" setting.
|
7 |
+
it is the last row, we happen to know... */
|
8 |
+
.form-table tr:last-of-type > * {
|
9 |
+
padding: 0;
|
10 |
+
}
|
11 |
+
|
12 |
+
|
13 |
+
#converters li {
|
14 |
+
cursor: move;
|
15 |
+
border: 1px solid #e5e5e5;
|
16 |
+
box-shadow: 0 1px 1px rgba(0,0,0,.04);
|
17 |
+
line-height: 1.4em;
|
18 |
+
background-color: #fafafa;
|
19 |
+
padding: 10px;
|
20 |
+
max-width: 400px;
|
21 |
+
}
|
22 |
+
#converters li:hover {
|
23 |
+
border-color: #999;
|
24 |
+
box-shadow: 0 1px 2px rgba(0,0,0,.1);
|
25 |
+
}
|
26 |
+
#converters li.deactivated,
|
27 |
+
#converters li.deactivated a.configure-converter,
|
28 |
+
#converters li.deactivated a.test-converter {
|
29 |
+
color: #aaa;
|
30 |
+
}
|
31 |
+
#converters li a {
|
32 |
+
cursor: pointer;
|
33 |
+
}
|
34 |
+
|
35 |
+
|
36 |
+
|
37 |
+
|
38 |
+
|
39 |
+
#converters li > * {
|
40 |
+
vertical-align: middle;
|
41 |
+
|
42 |
+
}
|
43 |
+
#converters li > span {
|
44 |
+
display: inline-block;
|
45 |
+
line-height: 1;
|
46 |
+
}
|
47 |
+
#converters li > span.text {
|
48 |
+
font-size: 15px;
|
49 |
+
padding-left: 10px;
|
50 |
+
width: 165px;
|
51 |
+
}
|
52 |
+
|
53 |
+
#converters li > a.btn {
|
54 |
+
/* border: 1px solid transparent;
|
55 |
+
border-radius: 8px;
|
56 |
+
*/
|
57 |
+
padding: 2px 6px;
|
58 |
+
margin-right: 4px;
|
59 |
+
text-decoration: none;
|
60 |
+
}
|
61 |
+
|
62 |
+
#converters li > a.btn:hover {
|
63 |
+
text-decoration: underline;
|
64 |
+
/*border-color: #666;
|
65 |
+
background-color: #eee;*/
|
66 |
+
}
|
67 |
+
#converters li > a.configure-converter {
|
68 |
+
|
69 |
+
|
70 |
+
}
|
71 |
+
|
72 |
+
/*
|
73 |
+
#converters li > a.remove-converter {
|
74 |
+
color: red;
|
75 |
+
}*/
|
76 |
+
|
77 |
+
|
78 |
+
.converter-options label {
|
79 |
+
min-width: 80px;
|
80 |
+
display: inline-block;
|
81 |
+
}
|
82 |
+
|
83 |
+
.converter-options .info {
|
84 |
+
margin-bottom: 20px;
|
85 |
+
}
|
86 |
+
.converter-options button {
|
87 |
+
margin-top: 15px;
|
88 |
+
}
|
images/drag-reorder.svg
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" standalone="no"?>
|
2 |
+
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
|
3 |
+
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
|
4 |
+
<svg version="1.0" xmlns="http://www.w3.org/2000/svg"
|
5 |
+
width="50.000000pt" height="50.000000pt" viewBox="0 0 50.000000 50.000000"
|
6 |
+
preserveAspectRatio="xMidYMid meet">
|
7 |
+
<metadata>
|
8 |
+
Created by potrace 1.15, written by Peter Selinger 2001-2017
|
9 |
+
</metadata>
|
10 |
+
<g transform="translate(0.000000,50.000000) scale(0.100000,-0.100000)"
|
11 |
+
fill="#000000" stroke="none">
|
12 |
+
<path d="M0 345 l0 -25 250 0 250 0 0 25 0 25 -250 0 -250 0 0 -25z"/>
|
13 |
+
<path d="M0 250 c0 -19 7 -20 250 -20 243 0 250 1 250 20 0 19 -7 20 -250 20
|
14 |
+
-243 0 -250 -1 -250 -20z"/>
|
15 |
+
<path d="M0 155 l0 -25 250 0 250 0 0 25 0 25 -250 0 -250 0 0 -25z"/>
|
16 |
+
</g>
|
17 |
+
</svg>
|
js/sortable.min.js
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
1 |
+
/*! Sortable 1.7.0 - MIT | git://github.com/rubaxa/Sortable.git */
|
2 |
+
|
3 |
+
!function(t){"use strict";"function"==typeof define&&define.amd?define(t):"undefined"!=typeof module&&void 0!==module.exports?module.exports=t():window.Sortable=t()}(function(){"use strict";if("undefined"==typeof window||!window.document)return function(){throw new Error("Sortable.js requires a window with a document")};var t,e,n,o,i,r,a,l,s,c,d,h,u,f,p,g,v,m,_,b,D,y={},w=/\s+/g,T=/left|right|inline/,S="Sortable"+(new Date).getTime(),C=window,E=C.document,x=C.parseInt,k=C.setTimeout,N=C.jQuery||C.Zepto,B=C.Polymer,P=!1,Y="draggable"in E.createElement("div"),X=!navigator.userAgent.match(/(?:Trident.*rv[ :]?11\.|msie)/i)&&((D=E.createElement("x")).style.cssText="pointer-events:auto","auto"===D.style.pointerEvents),O=!1,I=Math.abs,M=Math.min,A=[],R=[],L=function(){return!1},F=ot(function(t,e,n){if(n&&e.scroll){var o,i,r,a,d,h,u=n[S],f=e.scrollSensitivity,p=e.scrollSpeed,g=t.clientX,v=t.clientY,m=window.innerWidth,b=window.innerHeight;if(s!==n&&(l=e.scroll,s=n,c=e.scrollFn,!0===l)){l=n;do{if(l.offsetWidth<l.scrollWidth||l.offsetHeight<l.scrollHeight)break}while(l=l.parentNode)}l&&(o=l,i=l.getBoundingClientRect(),r=(I(i.right-g)<=f)-(I(i.left-g)<=f),a=(I(i.bottom-v)<=f)-(I(i.top-v)<=f)),r||a||(a=(b-v<=f)-(v<=f),((r=(m-g<=f)-(g<=f))||a)&&(o=C)),y.vx===r&&y.vy===a&&y.el===o||(y.el=o,y.vx=r,y.vy=a,clearInterval(y.pid),o&&(y.pid=setInterval(function(){h=a?a*p:0,d=r?r*p:0,"function"==typeof c&&"continue"!==c.call(u,d,h,t,_,o)||(o===C?C.scrollTo(C.pageXOffset+d,C.pageYOffset+h):(o.scrollTop+=h,o.scrollLeft+=d))},24)))}},30),H=function(t){function e(t,e){return null!=t&&!0!==t||null!=(t=n.name)?"function"==typeof t?t:function(n,o){var i=o.options.group.name;return e?t:t&&(t.join?t.indexOf(i)>-1:i==t)}:L}var n={},o=t.group;o&&"object"==typeof o||(o={name:o}),n.name=o.name,n.checkPull=e(o.pull,!0),n.checkPut=e(o.put),n.revertClone=o.revertClone,t.group=n};try{window.addEventListener("test",null,Object.defineProperty({},"passive",{get:function(){P={capture:!1,passive:!1}}}))}catch(t){}function W(t,e){if(!t||!t.nodeType||1!==t.nodeType)throw"Sortable: `el` must be HTMLElement, and not "+{}.toString.call(t);this.el=t,this.options=e=it({},e),t[S]=this;var n={group:null,sort:!0,disabled:!1,store:null,handle:null,scroll:!0,scrollSensitivity:30,scrollSpeed:10,draggable:/[uo]l/i.test(t.nodeName)?"li":">*",ghostClass:"sortable-ghost",chosenClass:"sortable-chosen",dragClass:"sortable-drag",ignore:"a, img",filter:null,preventOnFilter:!0,animation:0,setData:function(t,e){t.setData("Text",e.textContent)},dropBubble:!1,dragoverBubble:!1,dataIdAttr:"data-id",delay:0,forceFallback:!1,fallbackClass:"sortable-fallback",fallbackOnBody:!1,fallbackTolerance:0,fallbackOffset:{x:0,y:0},supportPointer:!1!==W.supportPointer};for(var o in n)!(o in e)&&(e[o]=n[o]);H(e);for(var i in this)"_"===i.charAt(0)&&"function"==typeof this[i]&&(this[i]=this[i].bind(this));this.nativeDraggable=!e.forceFallback&&Y,V(t,"mousedown",this._onTapStart),V(t,"touchstart",this._onTapStart),e.supportPointer&&V(t,"pointerdown",this._onTapStart),this.nativeDraggable&&(V(t,"dragover",this),V(t,"dragenter",this)),R.push(this._onDragOver),e.store&&this.sort(e.store.get(this))}function j(e,n){"clone"!==e.lastPullMode&&(n=!0),o&&o.state!==n&&(G(o,"display",n?"none":""),n||o.state&&(e.options.group.revertClone?(i.insertBefore(o,r),e._animate(t,o)):i.insertBefore(o,t)),o.state=n)}function U(t,e,n){if(t){n=n||E;do{if(">*"===e&&t.parentNode===n||nt(t,e))return t}while(void 0,t=(i=(o=t).host)&&i.nodeType?i:o.parentNode)}var o,i;return null}function V(t,e,n){t.addEventListener(e,n,P)}function q(t,e,n){t.removeEventListener(e,n,P)}function z(t,e,n){if(t)if(t.classList)t.classList[n?"add":"remove"](e);else{var o=(" "+t.className+" ").replace(w," ").replace(" "+e+" "," ");t.className=(o+(n?" "+e:"")).replace(w," ")}}function G(t,e,n){var o=t&&t.style;if(o){if(void 0===n)return E.defaultView&&E.defaultView.getComputedStyle?n=E.defaultView.getComputedStyle(t,""):t.currentStyle&&(n=t.currentStyle),void 0===e?n:n[e];e in o||(e="-webkit-"+e),o[e]=n+("string"==typeof n?"":"px")}}function Q(t,e,n){if(t){var o=t.getElementsByTagName(e),i=0,r=o.length;if(n)for(;i<r;i++)n(o[i],i);return o}return[]}function Z(t,e,n,i,r,a,l,s,c){t=t||e[S];var d=E.createEvent("Event"),h=t.options,u="on"+n.charAt(0).toUpperCase()+n.substr(1);d.initEvent(n,!0,!0),d.to=r||e,d.from=a||e,d.item=i||e,d.clone=o,d.oldIndex=l,d.newIndex=s,d.originalEvent=c,e.dispatchEvent(d),h[u]&&h[u].call(t,d)}function J(t,e,n,o,i,r,a,l){var s,c,d=t[S],h=d.options.onMove;return(s=E.createEvent("Event")).initEvent("move",!0,!0),s.to=e,s.from=t,s.dragged=n,s.draggedRect=o,s.related=i||e,s.relatedRect=r||e.getBoundingClientRect(),s.willInsertAfter=l,s.originalEvent=a,t.dispatchEvent(s),h&&(c=h.call(d,s,a)),c}function K(t){t.draggable=!1}function $(){O=!1}function tt(t){for(var e=t.tagName+t.className+t.src+t.href+t.textContent,n=e.length,o=0;n--;)o+=e.charCodeAt(n);return o.toString(36)}function et(t,e){var n=0;if(!t||!t.parentNode)return-1;for(;t&&(t=t.previousElementSibling);)"TEMPLATE"===t.nodeName.toUpperCase()||">*"!==e&&!nt(t,e)||n++;return n}function nt(t,e){if(t){if(t.matches)return t.matches(e);if(t.msMatchesSelector)return t.msMatchesSelector(e)}return!1}function ot(t,e){var n,o;return function(){void 0===n&&(n=arguments,o=this,k(function(){1===n.length?t.call(o,n[0]):t.apply(o,n),n=void 0},e))}}function it(t,e){if(t&&e)for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n]);return t}function rt(t){return B&&B.dom?B.dom(t).cloneNode(!0):N?N(t).clone(!0)[0]:t.cloneNode(!0)}function at(t){return k(t,0)}function lt(t){return clearTimeout(t)}return W.prototype={constructor:W,_onTapStart:function(e){var n,o=this,i=this.el,r=this.options,l=r.preventOnFilter,s=e.type,c=e.touches&&e.touches[0],d=(c||e).target,h=e.target.shadowRoot&&e.path&&e.path[0]||d,u=r.filter;if(function(t){A.length=0;var e=t.getElementsByTagName("input"),n=e.length;for(;n--;){var o=e[n];o.checked&&A.push(o)}}(i),!t&&!(/mousedown|pointerdown/.test(s)&&0!==e.button||r.disabled)&&!h.isContentEditable&&(d=U(d,r.draggable,i))&&a!==d){if(n=et(d,r.draggable),"function"==typeof u){if(u.call(this,e,d,this))return Z(o,h,"filter",d,i,i,n),void(l&&e.preventDefault())}else if(u&&(u=u.split(",").some(function(t){if(t=U(h,t.trim(),i))return Z(o,t,"filter",d,i,i,n),!0})))return void(l&&e.preventDefault());r.handle&&!U(h,r.handle,i)||this._prepareDragStart(e,c,d,n)}},_prepareDragStart:function(n,o,l,s){var c,d=this,h=d.el,u=d.options,p=h.ownerDocument;l&&!t&&l.parentNode===h&&(m=n,i=h,e=(t=l).parentNode,r=t.nextSibling,a=l,g=u.group,f=s,this._lastX=(o||n).clientX,this._lastY=(o||n).clientY,t.style["will-change"]="all",c=function(){d._disableDelayedDrag(),t.draggable=d.nativeDraggable,z(t,u.chosenClass,!0),d._triggerDragStart(n,o),Z(d,i,"choose",t,i,i,f)},u.ignore.split(",").forEach(function(e){Q(t,e.trim(),K)}),V(p,"mouseup",d._onDrop),V(p,"touchend",d._onDrop),V(p,"touchcancel",d._onDrop),V(p,"selectstart",d),u.supportPointer&&V(p,"pointercancel",d._onDrop),u.delay?(V(p,"mouseup",d._disableDelayedDrag),V(p,"touchend",d._disableDelayedDrag),V(p,"touchcancel",d._disableDelayedDrag),V(p,"mousemove",d._disableDelayedDrag),V(p,"touchmove",d._disableDelayedDrag),u.supportPointer&&V(p,"pointermove",d._disableDelayedDrag),d._dragStartTimer=k(c,u.delay)):c())},_disableDelayedDrag:function(){var t=this.el.ownerDocument;clearTimeout(this._dragStartTimer),q(t,"mouseup",this._disableDelayedDrag),q(t,"touchend",this._disableDelayedDrag),q(t,"touchcancel",this._disableDelayedDrag),q(t,"mousemove",this._disableDelayedDrag),q(t,"touchmove",this._disableDelayedDrag),q(t,"pointermove",this._disableDelayedDrag)},_triggerDragStart:function(e,n){(n=n||("touch"==e.pointerType?e:null))?(m={target:t,clientX:n.clientX,clientY:n.clientY},this._onDragStart(m,"touch")):this.nativeDraggable?(V(t,"dragend",this),V(i,"dragstart",this._onDragStart)):this._onDragStart(m,!0);try{E.selection?at(function(){E.selection.empty()}):window.getSelection().removeAllRanges()}catch(t){}},_dragStarted:function(){if(i&&t){var e=this.options;z(t,e.ghostClass,!0),z(t,e.dragClass,!1),W.active=this,Z(this,i,"start",t,i,i,f)}else this._nulling()},_emulateDragOver:function(){if(_){if(this._lastX===_.clientX&&this._lastY===_.clientY)return;this._lastX=_.clientX,this._lastY=_.clientY,X||G(n,"display","none");var t=E.elementFromPoint(_.clientX,_.clientY),e=t,o=R.length;if(t&&t.shadowRoot&&(e=t=t.shadowRoot.elementFromPoint(_.clientX,_.clientY)),e)do{if(e[S]){for(;o--;)R[o]({clientX:_.clientX,clientY:_.clientY,target:t,rootEl:e});break}t=e}while(e=e.parentNode);X||G(n,"display","")}},_onTouchMove:function(t){if(m){var e=this.options,o=e.fallbackTolerance,i=e.fallbackOffset,r=t.touches?t.touches[0]:t,a=r.clientX-m.clientX+i.x,l=r.clientY-m.clientY+i.y,s=t.touches?"translate3d("+a+"px,"+l+"px,0)":"translate("+a+"px,"+l+"px)";if(!W.active){if(o&&M(I(r.clientX-this._lastX),I(r.clientY-this._lastY))<o)return;this._dragStarted()}this._appendGhost(),b=!0,_=r,G(n,"webkitTransform",s),G(n,"mozTransform",s),G(n,"msTransform",s),G(n,"transform",s),t.preventDefault()}},_appendGhost:function(){if(!n){var e,o=t.getBoundingClientRect(),r=G(t),a=this.options;z(n=t.cloneNode(!0),a.ghostClass,!1),z(n,a.fallbackClass,!0),z(n,a.dragClass,!0),G(n,"top",o.top-x(r.marginTop,10)),G(n,"left",o.left-x(r.marginLeft,10)),G(n,"width",o.width),G(n,"height",o.height),G(n,"opacity","0.8"),G(n,"position","fixed"),G(n,"zIndex","100000"),G(n,"pointerEvents","none"),a.fallbackOnBody&&E.body.appendChild(n)||i.appendChild(n),e=n.getBoundingClientRect(),G(n,"width",2*o.width-e.width),G(n,"height",2*o.height-e.height)}},_onDragStart:function(e,n){var r=this,a=e.dataTransfer,l=r.options;r._offUpEvents(),g.checkPull(r,r,t,e)&&((o=rt(t)).draggable=!1,o.style["will-change"]="",G(o,"display","none"),z(o,r.options.chosenClass,!1),r._cloneId=at(function(){i.insertBefore(o,t),Z(r,i,"clone",t)})),z(t,l.dragClass,!0),n?("touch"===n?(V(E,"touchmove",r._onTouchMove),V(E,"touchend",r._onDrop),V(E,"touchcancel",r._onDrop),l.supportPointer&&(V(E,"pointermove",r._onTouchMove),V(E,"pointerup",r._onDrop))):(V(E,"mousemove",r._onTouchMove),V(E,"mouseup",r._onDrop)),r._loopId=setInterval(r._emulateDragOver,50)):(a&&(a.effectAllowed="move",l.setData&&l.setData.call(r,a,t)),V(E,"drop",r),r._dragStartId=at(r._dragStarted))},_onDragOver:function(a){var l,s,c,f,p,m,_=this.el,D=this.options,y=D.group,w=W.active,C=g===y,E=!1,x=D.sort;if((void 0!==a.preventDefault&&(a.preventDefault(),!D.dragoverBubble&&a.stopPropagation()),!t.animated)&&(b=!0,w&&!D.disabled&&(C?x||(f=!i.contains(t)):v===this||(w.lastPullMode=g.checkPull(this,w,t,a))&&y.checkPut(this,w,t,a))&&(void 0===a.rootEl||a.rootEl===this.el))){if(F(a,D,this.el),O)return;if(l=U(a.target,D.draggable,_),s=t.getBoundingClientRect(),v!==this&&(v=this,E=!0),f)return j(w,!0),e=i,void(o||r?i.insertBefore(t,o||r):x||i.appendChild(t));if(0===_.children.length||_.children[0]===n||_===a.target&&(p=a,m=_.lastElementChild.getBoundingClientRect(),p.clientY-(m.top+m.height)>5||p.clientX-(m.left+m.width)>5)){if(0!==_.children.length&&_.children[0]!==n&&_===a.target&&(l=_.lastElementChild),l){if(l.animated)return;c=l.getBoundingClientRect()}j(w,C),!1!==J(i,_,t,s,l,c,a)&&(t.contains(_)||(_.appendChild(t),e=_),this._animate(s,t),l&&this._animate(c,l))}else if(l&&!l.animated&&l!==t&&void 0!==l.parentNode[S]){d!==l&&(d=l,h=G(l),u=G(l.parentNode));var N=(c=l.getBoundingClientRect()).right-c.left,B=c.bottom-c.top,P=T.test(h.cssFloat+h.display)||"flex"==u.display&&0===u["flex-direction"].indexOf("row"),Y=l.offsetWidth>t.offsetWidth,X=l.offsetHeight>t.offsetHeight,I=(P?(a.clientX-c.left)/N:(a.clientY-c.top)/B)>.5,M=l.nextElementSibling,A=!1;if(P){var R=t.offsetTop,L=l.offsetTop;A=R===L?l.previousElementSibling===t&&!Y||I&&Y:l.previousElementSibling===t||t.previousElementSibling===l?(a.clientY-c.top)/B>.5:L>R}else E||(A=M!==t&&!X||I&&X);var H=J(i,_,t,s,l,c,a,A);!1!==H&&(1!==H&&-1!==H||(A=1===H),O=!0,k($,30),j(w,C),t.contains(_)||(A&&!M?_.appendChild(t):l.parentNode.insertBefore(t,A?M:l)),e=t.parentNode,this._animate(s,t),this._animate(c,l))}}},_animate:function(t,e){var n=this.options.animation;if(n){var o=e.getBoundingClientRect();1===t.nodeType&&(t=t.getBoundingClientRect()),G(e,"transition","none"),G(e,"transform","translate3d("+(t.left-o.left)+"px,"+(t.top-o.top)+"px,0)"),e.offsetWidth,G(e,"transition","all "+n+"ms"),G(e,"transform","translate3d(0,0,0)"),clearTimeout(e.animated),e.animated=k(function(){G(e,"transition",""),G(e,"transform",""),e.animated=!1},n)}},_offUpEvents:function(){var t=this.el.ownerDocument;q(E,"touchmove",this._onTouchMove),q(E,"pointermove",this._onTouchMove),q(t,"mouseup",this._onDrop),q(t,"touchend",this._onDrop),q(t,"pointerup",this._onDrop),q(t,"touchcancel",this._onDrop),q(t,"pointercancel",this._onDrop),q(t,"selectstart",this)},_onDrop:function(a){var l=this.el,s=this.options;clearInterval(this._loopId),clearInterval(y.pid),clearTimeout(this._dragStartTimer),lt(this._cloneId),lt(this._dragStartId),q(E,"mouseover",this),q(E,"mousemove",this._onTouchMove),this.nativeDraggable&&(q(E,"drop",this),q(l,"dragstart",this._onDragStart)),this._offUpEvents(),a&&(b&&(a.preventDefault(),!s.dropBubble&&a.stopPropagation()),n&&n.parentNode&&n.parentNode.removeChild(n),i!==e&&"clone"===W.active.lastPullMode||o&&o.parentNode&&o.parentNode.removeChild(o),t&&(this.nativeDraggable&&q(t,"dragend",this),K(t),t.style["will-change"]="",z(t,this.options.ghostClass,!1),z(t,this.options.chosenClass,!1),Z(this,i,"unchoose",t,e,i,f,null,a),i!==e?(p=et(t,s.draggable))>=0&&(Z(null,e,"add",t,e,i,f,p,a),Z(this,i,"remove",t,e,i,f,p,a),Z(null,e,"sort",t,e,i,f,p,a),Z(this,i,"sort",t,e,i,f,p,a)):t.nextSibling!==r&&(p=et(t,s.draggable))>=0&&(Z(this,i,"update",t,e,i,f,p,a),Z(this,i,"sort",t,e,i,f,p,a)),W.active&&(null!=p&&-1!==p||(p=f),Z(this,i,"end",t,e,i,f,p,a),this.save()))),this._nulling()},_nulling:function(){i=t=e=n=r=o=a=l=s=m=_=b=p=d=h=v=g=W.active=null,A.forEach(function(t){t.checked=!0}),A.length=0},handleEvent:function(e){switch(e.type){case"drop":case"dragend":this._onDrop(e);break;case"dragover":case"dragenter":t&&(this._onDragOver(e),function(t){t.dataTransfer&&(t.dataTransfer.dropEffect="move");t.preventDefault()}(e));break;case"mouseover":this._onDrop(e);break;case"selectstart":e.preventDefault()}},toArray:function(){for(var t,e=[],n=this.el.children,o=0,i=n.length,r=this.options;o<i;o++)U(t=n[o],r.draggable,this.el)&&e.push(t.getAttribute(r.dataIdAttr)||tt(t));return e},sort:function(t){var e={},n=this.el;this.toArray().forEach(function(t,o){var i=n.children[o];U(i,this.options.draggable,n)&&(e[t]=i)},this),t.forEach(function(t){e[t]&&(n.removeChild(e[t]),n.appendChild(e[t]))})},save:function(){var t=this.options.store;t&&t.set(this)},closest:function(t,e){return U(t,e||this.options.draggable,this.el)},option:function(t,e){var n=this.options;if(void 0===e)return n[t];n[t]=e,"group"===t&&H(n)},destroy:function(){var t=this.el;t[S]=null,q(t,"mousedown",this._onTapStart),q(t,"touchstart",this._onTapStart),q(t,"pointerdown",this._onTapStart),this.nativeDraggable&&(q(t,"dragover",this),q(t,"dragenter",this)),Array.prototype.forEach.call(t.querySelectorAll("[draggable]"),function(t){t.removeAttribute("draggable")}),R.splice(R.indexOf(this._onDragOver),1),this._onDrop(),this.el=t=null}},V(E,"touchmove",function(t){W.active&&t.preventDefault()}),W.utils={on:V,off:q,css:G,find:Q,is:function(t,e){return!!U(t,e,t)},extend:it,throttle:ot,closest:U,toggleClass:z,clone:rt,index:et,nextTick:at,cancelNextTick:lt},W.create=function(t,e){return new W(t,e)},W.version="1.7.0",W});
|
js/webp-express-options-page.js
ADDED
@@ -0,0 +1,342 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
/*window.converters = [
|
3 |
+
{
|
4 |
+
'converter': 'imagick',
|
5 |
+
},
|
6 |
+
{
|
7 |
+
'converter': 'cwebp',
|
8 |
+
},
|
9 |
+
{
|
10 |
+
'converter': 'gd',
|
11 |
+
},
|
12 |
+
{
|
13 |
+
'converter': 'ewww',
|
14 |
+
'options': {
|
15 |
+
'key': 'your api key here',
|
16 |
+
},
|
17 |
+
},
|
18 |
+
{
|
19 |
+
'converter': 'ewww',
|
20 |
+
'options': {
|
21 |
+
'key': 'your api key here 2',
|
22 |
+
},
|
23 |
+
},
|
24 |
+
{
|
25 |
+
'converter': 'wpc',
|
26 |
+
'options': {
|
27 |
+
'url': 'http://',
|
28 |
+
'secret': 'banana',
|
29 |
+
},
|
30 |
+
}
|
31 |
+
];*/
|
32 |
+
|
33 |
+
// Map of converters (are updated with updateConvertersMap)
|
34 |
+
window.convertersMap = {};
|
35 |
+
|
36 |
+
window.currentlyEditing = '';
|
37 |
+
|
38 |
+
window.defaultConverters = [
|
39 |
+
{
|
40 |
+
'converter': 'cwebp',
|
41 |
+
'options': {
|
42 |
+
'use-nice': false
|
43 |
+
},
|
44 |
+
},
|
45 |
+
{
|
46 |
+
'converter': 'wpc',
|
47 |
+
},
|
48 |
+
{
|
49 |
+
'converter': 'gd',
|
50 |
+
'options': {
|
51 |
+
'skip-pngs': true
|
52 |
+
},
|
53 |
+
},
|
54 |
+
{
|
55 |
+
'converter': 'ewww',
|
56 |
+
},
|
57 |
+
{
|
58 |
+
'converter': 'imagick',
|
59 |
+
},
|
60 |
+
]
|
61 |
+
|
62 |
+
function resetToDefaultConverters() {
|
63 |
+
window.converters = window.defaultConverters;
|
64 |
+
}
|
65 |
+
|
66 |
+
function addMissingConverters() {
|
67 |
+
// check if all available converters are in the array.
|
68 |
+
// if not - add!
|
69 |
+
// the double loop could be avoided with map. But arrays are so small, so not worth it
|
70 |
+
for (var i=0; i<window.defaultConverters.length; i++) {
|
71 |
+
var checkMe = window.defaultConverters[i]['converter'];
|
72 |
+
var found = false;
|
73 |
+
for (var j=0; j<window.converters.length; j++) {
|
74 |
+
if (window.converters[j]['converter'] == checkMe) {
|
75 |
+
found = true;
|
76 |
+
}
|
77 |
+
}
|
78 |
+
if (!found) {
|
79 |
+
window.converters.push(window.defaultConverters[i]);
|
80 |
+
}
|
81 |
+
|
82 |
+
}
|
83 |
+
}
|
84 |
+
function generateConverterHTML(converter) {
|
85 |
+
html = '<li data-id="' + converter['id'] + '" class="' + (converter.deactivated ? 'deactivated' : '') + '">';
|
86 |
+
//html += '<svg version="1.0" xmlns="http://www.w3.org/2000/svg" width="17px" height="17px" viewBox="0 0 100.000000 100.000000" preserveAspectRatio="xMidYMid meet"><g transform="translate(0.000000,100.000000) scale(0.100000,-0.100000)" fill="#444444" stroke="none"><path d="M415 920 l-80 -80 165 0 165 0 -80 80 c-44 44 -82 80 -85 80 -3 0 -41 -36 -85 -80z"/><path d="M0 695 l0 -45 500 0 500 0 0 45 0 45 -500 0 -500 0 0 -45z"/><path d="M0 500 l0 -40 500 0 500 0 0 40 0 40 -500 0 -500 0 0 -40z"/><path d="M0 305 l0 -45 500 0 500 0 0 45 0 45 -500 0 -500 0 0 -45z"/><path d="M418 78 l82 -83 82 83 83 82 -165 0 -165 0 83 -82z"/></g></svg>';
|
87 |
+
// html += '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M20 9H4v2h16V9zM4 15h16v-2H4v2z"/></svg>';
|
88 |
+
// html += '<svg version="1.0" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 100.000000 100.000000" preserveAspectRatio="xMidYMid meet"><g transform="translate(0.000000,100.000000) scale(0.100000,-0.100000)" fill="#888888" stroke="none"><path d="M415 920 l-80 -80 165 0 165 0 -80 80 c-44 44 -82 80 -85 80 -3 0 -41 -36 -85 -80z"/><path d="M0 695 l0 -45 500 0 500 0 0 45 0 45 -500 0 -500 0 0 -45z"/><path d="M0 500 l0 -40 500 0 500 0 0 40 0 40 -500 0 -500 0 0 -40z"/><path d="M0 305 l0 -45 500 0 500 0 0 45 0 45 -500 0 -500 0 0 -45z"/><path d="M418 78 l82 -83 82 83 83 82 -165 0 -165 0 83 -82z"/></g></svg>';
|
89 |
+
html += '<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18"><path d="M2 13.5h14V12H2v1.5zm0-4h14V8H2v1.5zM2 4v1.5h14V4H2z"/></svg>';
|
90 |
+
html += '<span class="text">' + converter['id'] + '</span>';
|
91 |
+
html += '<a class="configure-converter btn" onclick="configureConverter(\'' + converter['id'] + '\')">configure</a>';
|
92 |
+
html += '<a class="test-converter btn" onclick="testConverter(\'' + converter['id'] + '\')">test</a>';
|
93 |
+
|
94 |
+
if (converter.deactivated) {
|
95 |
+
html += '<a class="activate-converter btn" onclick=activateConverter(\'' + converter['id'] + '\')>activate</a>';
|
96 |
+
}
|
97 |
+
else {
|
98 |
+
html += '<a class="deactivate-converter btn" onclick=deactivateConverter(\'' + converter['id'] + '\')>deactivate</a>';
|
99 |
+
}
|
100 |
+
|
101 |
+
/*
|
102 |
+
switch (converter['converter']) {
|
103 |
+
case 'ewww':
|
104 |
+
case 'wpc':
|
105 |
+
html += '<a class="remove-converter btn" onclick=removeConverter(\'' + converter['id'] + '\')>remove</a>';
|
106 |
+
break;
|
107 |
+
case 'cwebp':
|
108 |
+
case 'imagick':
|
109 |
+
case 'gd':
|
110 |
+
break;
|
111 |
+
}*/
|
112 |
+
html += '</li>';
|
113 |
+
return html;
|
114 |
+
}
|
115 |
+
|
116 |
+
/* Set ids on global converters object */
|
117 |
+
function setTemporaryIdsOnConverters() {
|
118 |
+
var numConverterInstances = [];
|
119 |
+
for (var i=0; i<converters.length; i++) {
|
120 |
+
var converter = converters[i]['converter'];
|
121 |
+
if (numConverterInstances[converter]) {
|
122 |
+
numConverterInstances[converter]++;
|
123 |
+
window.converters[i]['id'] = converter + '-' + numConverterInstances[converter];
|
124 |
+
}
|
125 |
+
else {
|
126 |
+
numConverterInstances[converter] = 1;
|
127 |
+
window.converters[i]['id'] = converter;
|
128 |
+
}
|
129 |
+
}
|
130 |
+
//alert(JSON.stringify(window.converters));
|
131 |
+
updateConvertersMap();
|
132 |
+
}
|
133 |
+
|
134 |
+
function updateConvertersMap() {
|
135 |
+
var map = {};
|
136 |
+
for (var i=0; i<window.converters.length; i++) {
|
137 |
+
var converter = window.converters[i];
|
138 |
+
map[converter['id']] = converter;
|
139 |
+
}
|
140 |
+
window.convertersMap = map;
|
141 |
+
}
|
142 |
+
|
143 |
+
function reorderConverters(order) {
|
144 |
+
|
145 |
+
// Create new converter array
|
146 |
+
var result = [];
|
147 |
+
for (var i=0; i<order.length; i++) {
|
148 |
+
result.push(window.convertersMap[order[i]]);
|
149 |
+
}
|
150 |
+
//alert(JSON.stringify(result));
|
151 |
+
window.converters = result;
|
152 |
+
updateInputValue();
|
153 |
+
}
|
154 |
+
|
155 |
+
/* Update the hidden input containing all the data */
|
156 |
+
function updateInputValue() {
|
157 |
+
document.getElementsByName('webp_express_converters')[0].value = JSON.stringify(window.converters);
|
158 |
+
}
|
159 |
+
|
160 |
+
function setConvertersHTML() {
|
161 |
+
|
162 |
+
var html = '';
|
163 |
+
|
164 |
+
setTemporaryIdsOnConverters();
|
165 |
+
|
166 |
+
for (var i=0; i<window.converters.length; i++) {
|
167 |
+
var converter = converters[i];
|
168 |
+
html += generateConverterHTML(converter);
|
169 |
+
}
|
170 |
+
|
171 |
+
var el = document.getElementById('converters');
|
172 |
+
el.innerHTML = html;
|
173 |
+
|
174 |
+
var sortable = Sortable.create(el, {
|
175 |
+
store: {
|
176 |
+
get: function() {
|
177 |
+
var order = [];
|
178 |
+
for (var i=0; i<window.converters.length; i++) {
|
179 |
+
order.push(window.converters[i]['id']);
|
180 |
+
}
|
181 |
+
return order;
|
182 |
+
},
|
183 |
+
set: function(sortable) {
|
184 |
+
var order = sortable.toArray();
|
185 |
+
reorderConverters(order);
|
186 |
+
}
|
187 |
+
}
|
188 |
+
});
|
189 |
+
updateInputValue();
|
190 |
+
}
|
191 |
+
|
192 |
+
document.addEventListener('DOMContentLoaded', function() {
|
193 |
+
//resetToDefaultConverters();
|
194 |
+
addMissingConverters();
|
195 |
+
setConvertersHTML();
|
196 |
+
|
197 |
+
|
198 |
+
//alert(sortable.toArray());
|
199 |
+
});
|
200 |
+
|
201 |
+
function wpe_addCloudConverter(converter) {
|
202 |
+
|
203 |
+
}
|
204 |
+
|
205 |
+
function getConverterOption(converter, optionName, defaultValue) {
|
206 |
+
if ((converter['options'] == undefined) || (converter['options'][optionName] == undefined)) {
|
207 |
+
return defaultValue;
|
208 |
+
}
|
209 |
+
return converter['options'][optionName];
|
210 |
+
}
|
211 |
+
|
212 |
+
function setConverterOption(converter, optionName, value) {
|
213 |
+
if (converter['options'] == undefined) {
|
214 |
+
converter['options'] = {};
|
215 |
+
}
|
216 |
+
converter['options'][optionName] = value;
|
217 |
+
}
|
218 |
+
|
219 |
+
function configureConverter(id) {
|
220 |
+
var converter = window.convertersMap[id];
|
221 |
+
window.currentlyEditing = id;
|
222 |
+
|
223 |
+
switch (converter['converter']) {
|
224 |
+
case 'ewww':
|
225 |
+
document.getElementById('ewww_key').value = getConverterOption(converter, 'key', '');
|
226 |
+
document.getElementById('ewww_key_2').value = getConverterOption(converter, 'key-2', '');
|
227 |
+
break;
|
228 |
+
case 'wpc':
|
229 |
+
document.getElementById('wpc_url').value = getConverterOption(converter, 'url', '');
|
230 |
+
document.getElementById('wpc_secret').value = getConverterOption(converter, 'secret', '');
|
231 |
+
document.getElementById('wpc_url_2').value = getConverterOption(converter, 'url-2', '');
|
232 |
+
document.getElementById('wpc_secret_2').value = getConverterOption(converter, 'secret-2', '');
|
233 |
+
break;
|
234 |
+
case 'gd':
|
235 |
+
document.getElementById('gd_skip_pngs').checked = getConverterOption(converter, 'skip-pngs', '');
|
236 |
+
break;
|
237 |
+
case 'cwebp':
|
238 |
+
document.getElementById('cwebp_use_nice').checked = getConverterOption(converter, 'use-nice', '');
|
239 |
+
break;
|
240 |
+
|
241 |
+
}
|
242 |
+
tb_show("Configure " + converter['id'] + ' converter', '#TB_inline?inlineId=' + converter['converter']);
|
243 |
+
}
|
244 |
+
|
245 |
+
function updateConverterOptions() {
|
246 |
+
var converter = window.convertersMap[window.currentlyEditing];
|
247 |
+
|
248 |
+
switch (converter['converter']) {
|
249 |
+
case 'ewww':
|
250 |
+
setConverterOption(converter, 'key', document.getElementById('ewww_key').value);
|
251 |
+
setConverterOption(converter, 'key-2', document.getElementById('ewww_key_2').value);
|
252 |
+
break;
|
253 |
+
case 'wpc':
|
254 |
+
setConverterOption(converter, 'url', document.getElementById('wpc_url').value);
|
255 |
+
setConverterOption(converter, 'secret', document.getElementById('wpc_secret').value);
|
256 |
+
setConverterOption(converter, 'url-2', document.getElementById('wpc_url_2').value);
|
257 |
+
setConverterOption(converter, 'secret-2', document.getElementById('wpc_secret_2').value);
|
258 |
+
break;
|
259 |
+
case 'gd':
|
260 |
+
setConverterOption(converter, 'skip-pngs', document.getElementById('gd_skip_pngs').checked);
|
261 |
+
break;
|
262 |
+
case 'cwebp':
|
263 |
+
setConverterOption(converter, 'use-nice', document.getElementById('cwebp_use_nice').checked);
|
264 |
+
break;
|
265 |
+
}
|
266 |
+
updateInputValue();
|
267 |
+
tb_remove();
|
268 |
+
}
|
269 |
+
|
270 |
+
function testConverter(id) {
|
271 |
+
//alert('h' + id);
|
272 |
+
var converter = window.convertersMap[id];
|
273 |
+
|
274 |
+
// https://stackoverflow.com/questions/4321068/to-invoke-thickbox-using-javascript
|
275 |
+
|
276 |
+
var urls = window.webpExpressPaths['urls'];
|
277 |
+
var paths = window.webpExpressPaths['filePaths'];
|
278 |
+
|
279 |
+
var url = urls['webpExpressRoot'] + '/test-run.php';
|
280 |
+
|
281 |
+
|
282 |
+
// test images here: http://nottinghamtec.co.uk/~aer/TestPatterns/1080/
|
283 |
+
filename = 'test.jpg';
|
284 |
+
filename = 'stones.jpg';
|
285 |
+
filename = 'architecture2.jpg';
|
286 |
+
filename = 'test1.png';
|
287 |
+
filename = 'focus.jpg';
|
288 |
+
|
289 |
+
url += '?source=' + paths['webpExpressRoot'] + '/test/' + filename;
|
290 |
+
url += '&destination=' + paths['destinationRoot'] + '/' + filename + '.webp';
|
291 |
+
url += '&destinationUrl=' + urls['destinationRoot'] + '/' + filename + '.webp';
|
292 |
+
url += '&converter=' + converter['converter'];
|
293 |
+
url += '&max-quality=' + document.getElementsByName('webp_express_max_quality')[0].value;
|
294 |
+
//url += '&method=' + document.getElementsByName('webp_express_method')[0].value;
|
295 |
+
|
296 |
+
if (converter.options) {
|
297 |
+
for (var option in converter.options) {
|
298 |
+
if (converter.options.hasOwnProperty(option)) {
|
299 |
+
//alert(option);
|
300 |
+
url += '&' + option + '=' + converter.options[option];
|
301 |
+
}
|
302 |
+
}
|
303 |
+
}
|
304 |
+
url += '&TB_iframe=true&width=400&height=300';
|
305 |
+
//alert(url);
|
306 |
+
tb_show("Test running converter: " + converter['id'], url);
|
307 |
+
}
|
308 |
+
|
309 |
+
/*
|
310 |
+
function removeConverter(id) {
|
311 |
+
for (var i=0; i<window.converters.length; i++) {
|
312 |
+
if (window.converters[i]['id'] == id) {
|
313 |
+
window.converters.splice(i, 1);
|
314 |
+
setConvertersHTML();
|
315 |
+
break;
|
316 |
+
}
|
317 |
+
}
|
318 |
+
}*/
|
319 |
+
|
320 |
+
function addConverter(id) {
|
321 |
+
window.converters.push({
|
322 |
+
converter: id
|
323 |
+
});
|
324 |
+
setConvertersHTML();
|
325 |
+
tb_remove();
|
326 |
+
}
|
327 |
+
|
328 |
+
function deactivateConverter(id) {
|
329 |
+
window.convertersMap[id].deactivated = true;
|
330 |
+
setConvertersHTML();
|
331 |
+
}
|
332 |
+
|
333 |
+
function activateConverter(id) {
|
334 |
+
delete window.convertersMap[id].deactivated
|
335 |
+
setConvertersHTML();
|
336 |
+
}
|
337 |
+
|
338 |
+
function addConverterClick() {
|
339 |
+
// width=600&height=550&inlineId=add-cloud-converter-id
|
340 |
+
var options = '#TB_inline?inlineId=add-cloud-converter-id';
|
341 |
+
tb_show("Add converter", options);
|
342 |
+
}
|
lib/activate.php
ADDED
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
include_once( plugin_dir_path( __FILE__ ) . 'helpers.php');
|
4 |
+
|
5 |
+
class WebPExpressActivate {
|
6 |
+
|
7 |
+
|
8 |
+
public function activate() {
|
9 |
+
|
10 |
+
update_option( 'webp-express-message-pending', true, false );
|
11 |
+
|
12 |
+
update_option( 'webp-express-just-activated', true, false );
|
13 |
+
|
14 |
+
|
15 |
+
if ( strpos( strtolower($_SERVER['SERVER_SOFTWARE']), 'microsoft-iis') !== false ) {
|
16 |
+
update_option( 'webp-express-microsoft-iis', true, false );
|
17 |
+
update_option( 'webp-express-deactivate', true, false );
|
18 |
+
return;
|
19 |
+
}
|
20 |
+
|
21 |
+
|
22 |
+
if ( strpos( strtolower($_SERVER['SERVER_SOFTWARE']), 'litespeed') !== false ) {
|
23 |
+
update_option( 'webp-express-not-tested-on-litespeed', true, false );
|
24 |
+
} else if (!( strpos( strtolower($_SERVER['SERVER_SOFTWARE']), 'apache') !== false )) {
|
25 |
+
update_option( 'webp-express-not-apache', true, false );
|
26 |
+
}
|
27 |
+
|
28 |
+
|
29 |
+
if ( is_multisite() ) {
|
30 |
+
update_option( 'webp-express-no-multisite', true, false );
|
31 |
+
update_option( 'webp-express-deactivate', true, false );
|
32 |
+
return;
|
33 |
+
}
|
34 |
+
|
35 |
+
if (!version_compare(PHP_VERSION, '5.5.0', '>=')) {
|
36 |
+
update_option( 'webp-express-php-too-old', true, false );
|
37 |
+
//update_option( 'webp-express-deactivate', true, false );
|
38 |
+
return;
|
39 |
+
}
|
40 |
+
|
41 |
+
|
42 |
+
// Create upload dir
|
43 |
+
$urlsAndPaths = WebPExpressHelpers::calculateUrlsAndPaths();
|
44 |
+
$ourUploadDir = $urlsAndPaths['filePaths']['uploadPath'];
|
45 |
+
|
46 |
+
if ( ! file_exists( $ourUploadDir ) ) {
|
47 |
+
wp_mkdir_p( $ourUploadDir );
|
48 |
+
}
|
49 |
+
if ( ! file_exists( $ourUploadDir ) ) {
|
50 |
+
update_option( 'webp-express-failed-creating-upload-dir', true, false );
|
51 |
+
update_option( 'webp-express-deactivate', true, false );
|
52 |
+
return;
|
53 |
+
}
|
54 |
+
|
55 |
+
// Add rules to .htaccess
|
56 |
+
$rules = WebPExpressHelpers::generateHTAccessRules();
|
57 |
+
WebPExpressHelpers::insertHTAccessRules($rules);
|
58 |
+
|
59 |
+
|
60 |
+
}
|
61 |
+
|
62 |
+
}
|
63 |
+
|
64 |
+
WebPExpressActivate::activate();
|
lib/deactivate.php
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
include_once( plugin_dir_path( __FILE__ ) . 'helpers.php');
|
3 |
+
|
4 |
+
class WebPExpressDeactivate {
|
5 |
+
|
6 |
+
public function deactivate() {
|
7 |
+
WebPExpressHelpers::insertHTAccessRules("# deactivated");
|
8 |
+
}
|
9 |
+
}
|
10 |
+
|
11 |
+
WebPExpressDeactivate::deactivate();
|
lib/helpers.php
ADDED
@@ -0,0 +1,190 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class WebPExpressHelpers
|
4 |
+
{
|
5 |
+
|
6 |
+
public static function calculateUrlsAndPaths()
|
7 |
+
{
|
8 |
+
// Calculate URL's
|
9 |
+
$upload_dir = wp_upload_dir();
|
10 |
+
$uploadUrlAbs = $upload_dir['baseurl'] . '/' . 'webp-express';
|
11 |
+
|
12 |
+
// Calculate url path to directory of image converter
|
13 |
+
$pluginUrlAbs = plugins_url('', WEBPEXPRESS_PLUGIN);
|
14 |
+
|
15 |
+
$converterUrlPath = parse_url($pluginUrlAbs)['path'];
|
16 |
+
|
17 |
+
// Calculate upload url path
|
18 |
+
$uploadUrlPath = parse_url($uploadUrlAbs)['path'];
|
19 |
+
|
20 |
+
// Calculate Wordpress url path
|
21 |
+
// If site for example is accessed example.com/blog/, then the url path is "blog"
|
22 |
+
$wpUrlPath = trailingslashit(parse_url(site_url())['path']); // ie "/blog/" or "/"
|
23 |
+
|
24 |
+
$converterUrlPathRelativeToSiteUrl = WebPExpressHelpers::get_rel_dir(untrailingslashit($wpUrlPath), $converterUrlPath);
|
25 |
+
$siteUrlPathRelativeToConverterPath = WebPExpressHelpers::get_rel_dir($converterUrlPath, untrailingslashit($wpUrlPath));
|
26 |
+
|
27 |
+
|
28 |
+
// Calculate file dirs
|
29 |
+
// --------------------
|
30 |
+
|
31 |
+
$uploadDir = trailingslashit($upload_dir['basedir']) . 'webp-express';
|
32 |
+
|
33 |
+
$uploadPathRelativeToWebExpressRoot = untrailingslashit(WebPExpressHelpers::get_rel_dir(WEBPEXPRESS_PLUGIN_DIR, $uploadDir));
|
34 |
+
|
35 |
+
return [
|
36 |
+
'urls' => [
|
37 |
+
'webpExpressRoot' => untrailingslashit($converterUrlPath),
|
38 |
+
'convert' => untrailingslashit($converterUrlPath) . 'convert.php',
|
39 |
+
'destinationRoot' => untrailingslashit($uploadUrlPath),
|
40 |
+
'wpRoot' => untrailingslashit($wpUrlPath), // ie "/blog" or ""
|
41 |
+
'converterUrlPathRelativeToSiteUrl' => $converterUrlPathRelativeToSiteUrl,
|
42 |
+
'siteUrlPathRelativeToConverterPath' => $siteUrlPathRelativeToConverterPath
|
43 |
+
],
|
44 |
+
'filePaths' => [
|
45 |
+
'destinationRoot' => untrailingslashit($uploadDir),
|
46 |
+
'webpExpressRoot' => untrailingslashit(WEBPEXPRESS_PLUGIN_DIR),
|
47 |
+
'uploadPath' => $uploadDir,
|
48 |
+
'uploadPathRelativeToWebExpressRoot' => $uploadPathRelativeToWebExpressRoot
|
49 |
+
]
|
50 |
+
];
|
51 |
+
}
|
52 |
+
|
53 |
+
public static function generateHTAccessRules()
|
54 |
+
{
|
55 |
+
$options = '';
|
56 |
+
$options .= '&max-quality=' . get_option('webp_express_max_quality');
|
57 |
+
//$options .= '&method=' . get_option('webp_express_method');
|
58 |
+
$options .= '&fail=' . get_option('webp_express_failure_response');
|
59 |
+
$options .= '&critical-fail=report';
|
60 |
+
|
61 |
+
$converters_and_options = json_decode(get_option('webp_express_converters'), true);
|
62 |
+
|
63 |
+
$converter_options = '';
|
64 |
+
foreach ($converters_and_options as $converter) {
|
65 |
+
if (isset($converter['deactivated'])) continue;
|
66 |
+
$converters[] = $converter['converter'];
|
67 |
+
if (isset($converter['options'])) {
|
68 |
+
foreach ($converter['options'] as $converter_option => $converter_value) {
|
69 |
+
$converter_options .= '&' . $converter['id'] . '-' . $converter_option . '=' . $converter_value;
|
70 |
+
}
|
71 |
+
};
|
72 |
+
}
|
73 |
+
$options .= '&converters=' . implode(',', $converters);
|
74 |
+
$options .= $converter_options;
|
75 |
+
|
76 |
+
$urlsAndPaths = WebPExpressHelpers::calculateUrlsAndPaths();
|
77 |
+
$urls = $urlsAndPaths['urls'];
|
78 |
+
$filePaths = $urlsAndPaths['filePaths'];
|
79 |
+
|
80 |
+
$imageTypes = get_option('webp_express_image_types_to_convert');
|
81 |
+
$fileExtensions = [];
|
82 |
+
if ($imageTypes & 1) {
|
83 |
+
$fileExtensions[] = 'jpe?g';
|
84 |
+
}
|
85 |
+
if ($imageTypes & 2) {
|
86 |
+
$fileExtensions[] = 'png';
|
87 |
+
}
|
88 |
+
$fileExt = implode('|', $fileExtensions);
|
89 |
+
|
90 |
+
if ($imageTypes == 0) {
|
91 |
+
$rules = '# Configured not to convert anything!';
|
92 |
+
//$rules .= 'php_value include_path ".:/usr/local/lib/php:/your/dir"';
|
93 |
+
$rules .= 'php_value include_path ".:/usr/local/lib/php:/hsphere/local/home/z84733/mingo.net/wp-content/plugins/webp-express/vendor/webp-convert/Converters/Binaries"';
|
94 |
+
} else {
|
95 |
+
$rules = "<IfModule mod_rewrite.c>\n" .
|
96 |
+
" RewriteEngine On\n" .
|
97 |
+
" RewriteCond %{HTTP_ACCEPT} image/webp\n" .
|
98 |
+
" RewriteCond %{QUERY_STRING} (^reconvert.*)|(^debug.*) [OR]\n" .
|
99 |
+
" RewriteCond %{DOCUMENT_ROOT}" . $urls['destinationRoot'] . "/$1.$2.webp !-f\n" .
|
100 |
+
" RewriteCond %{QUERY_STRING} (.*)\n" .
|
101 |
+
" RewriteRule ^(.*)\.(" . $fileExt . ")$ " . $urls['converterUrlPathRelativeToSiteUrl'] . "convert.php?source=" . $urls['siteUrlPathRelativeToConverterPath'] . "$1.$2&destination-root=" . $filePaths['uploadPathRelativeToWebExpressRoot'] . $options . "&%1 [NC,T=image/webp,E=accept:1]\n" .
|
102 |
+
" RewriteCond %{HTTP_ACCEPT} image/webp\n" .
|
103 |
+
" RewriteCond %{QUERY_STRING} !((^reconvert.*)|(^debug.*))\n" .
|
104 |
+
" RewriteCond %{DOCUMENT_ROOT}" . $urls['destinationRoot'] . "/$1.$2.webp -f\n" .
|
105 |
+
" RewriteRule ^(.*)\.(" . $fileExt . ")$ " . $urls['destinationRoot'] . "/$1.$2.webp [NC,T=image/webp,E=accept:1,QSD]\n" .
|
106 |
+
"</IfModule>\n" .
|
107 |
+
"<IfModule mod_headers.c>\n" .
|
108 |
+
" Header append Vary Accept env=REDIRECT_accept\n" .
|
109 |
+
"</IfModule>\n" .
|
110 |
+
"AddType image/webp .webp\n";
|
111 |
+
}
|
112 |
+
return $rules;
|
113 |
+
}
|
114 |
+
|
115 |
+
private static function doInsertHTAccessRules($rules) {
|
116 |
+
if (!function_exists('get_home_path')) {
|
117 |
+
require_once ABSPATH . 'wp-admin/includes/file.php';
|
118 |
+
}
|
119 |
+
$root_path = get_home_path();
|
120 |
+
|
121 |
+
if (!file_exists($root_path . '.htaccess')) {
|
122 |
+
return false;
|
123 |
+
}
|
124 |
+
|
125 |
+
$file_existing_permission = '';
|
126 |
+
|
127 |
+
// Try to make .htaccess writable if its not
|
128 |
+
if (file_exists($root_path . '.htaccess') && !is_writable($root_path . '.htaccess')) {
|
129 |
+
// Store existing permissions, so we can revert later
|
130 |
+
$file_existing_permission = octdec(substr(decoct(fileperms($root_path . '.htaccess')), -4));
|
131 |
+
|
132 |
+
// Try to chmod.
|
133 |
+
// It may fail, but we can ignore that. If it fails, insert_with_markers will also fail
|
134 |
+
chmod($root_path . '.htaccess', 0550);
|
135 |
+
}
|
136 |
+
|
137 |
+
|
138 |
+
/* Add rules to .htaccess */
|
139 |
+
if (!function_exists('insert_with_markers')) {
|
140 |
+
require_once ABSPATH . 'wp-admin/includes/misc.php';
|
141 |
+
}
|
142 |
+
if (!insert_with_markers($root_path . '.htaccess', 'WebP Express', $rules)) {
|
143 |
+
return false;
|
144 |
+
}
|
145 |
+
else {
|
146 |
+
/* Revert File Permission */
|
147 |
+
if (!empty($file_existing_permission)) {
|
148 |
+
chmod($root_path . '.htaccess', $file_existing_permission);
|
149 |
+
}
|
150 |
+
return true;
|
151 |
+
}
|
152 |
+
|
153 |
+
}
|
154 |
+
|
155 |
+
public static function insertHTAccessRules($rules)
|
156 |
+
{
|
157 |
+
if (self::doInsertHTAccessRules($rules)) {
|
158 |
+
update_option('webp-express-message-pending', true, false );
|
159 |
+
update_option('webp-express-inserted-rules-ok', true, false);
|
160 |
+
} else {
|
161 |
+
update_option('webp-express-failed-inserting-rules', true, false);
|
162 |
+
update_option('webp-express-deactivate', true, false);
|
163 |
+
}
|
164 |
+
}
|
165 |
+
|
166 |
+
/* Get relative path between one dir and the other.
|
167 |
+
ie
|
168 |
+
from: /var/www/wordpress/wp-content/plugins/webp-express
|
169 |
+
to: /var/www/wordpress/wp-content/uploads
|
170 |
+
result: ../../uploads/
|
171 |
+
*/
|
172 |
+
public static function get_rel_dir($from_dir, $to_dir) {
|
173 |
+
$from_dir_parts = explode('/', str_replace( '\\', '/', $from_dir ));
|
174 |
+
$to_dir_parts = explode('/', str_replace( '\\', '/', $to_dir ));
|
175 |
+
$i = 0;
|
176 |
+
while (($i < count($from_dir_parts)) && ($i < count($to_dir_parts)) && ($from_dir_parts[$i] == $to_dir_parts[$i])) {
|
177 |
+
$i++;
|
178 |
+
}
|
179 |
+
$rel = "";
|
180 |
+
for ($j = $i; $j < count($from_dir_parts); $j++) {
|
181 |
+
$rel .= "../";
|
182 |
+
}
|
183 |
+
|
184 |
+
for ($j = $i; $j < count($to_dir_parts); $j++) {
|
185 |
+
$rel .= $to_dir_parts[$j] . '/';
|
186 |
+
}
|
187 |
+
return $rel;
|
188 |
+
}
|
189 |
+
|
190 |
+
}
|
lib/message.php
ADDED
@@ -0,0 +1,141 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
delete_option( 'webp-express-message-pending');
|
4 |
+
|
5 |
+
if ( get_option( 'webp-express-deactivate' ) ) {
|
6 |
+
add_action( 'admin_notices', function() {
|
7 |
+
printf(
|
8 |
+
'<div class="%1$s"><p>%2$s</p></div>',
|
9 |
+
esc_attr( 'notice notice-error is-dismissible' ),
|
10 |
+
__( 'Plugin <b>deactivated</b>' )
|
11 |
+
);
|
12 |
+
});
|
13 |
+
}
|
14 |
+
|
15 |
+
add_action( 'admin_notices', function() {
|
16 |
+
// Possible classes:
|
17 |
+
// notice-warning, notice-error, notice-warning, notice-success, or notice-info
|
18 |
+
// - add is-dismissible
|
19 |
+
|
20 |
+
if ( get_option( 'webp-express-inserted-rules-ok' ) ) {
|
21 |
+
delete_option( 'webp-express-inserted-rules-ok');
|
22 |
+
printf(
|
23 |
+
'<div class="%1$s"><p>%2$s</p></div>',
|
24 |
+
esc_attr( 'notice notice-success is-dismissible' ),
|
25 |
+
esc_html( __( 'WebP Express updated .htaccess', 'webp-express' ) )
|
26 |
+
);
|
27 |
+
}
|
28 |
+
|
29 |
+
|
30 |
+
if ( get_option( 'webp-express-just-activated' ) ) {
|
31 |
+
delete_option( 'webp-express-just-activated');
|
32 |
+
|
33 |
+
|
34 |
+
if ( get_option( 'webp-express-microsoft-iis' ) ) {
|
35 |
+
delete_option( 'webp-express-microsoft-iis');
|
36 |
+
printf(
|
37 |
+
'<div class="%1$s"><p>%2$s</p></div>',
|
38 |
+
esc_attr( 'notice notice-error is-dismissible' ),
|
39 |
+
esc_html( __( 'You are on Microsof IIS server. The plugin does not work on IIS', 'webp-express' ) )
|
40 |
+
);
|
41 |
+
return;
|
42 |
+
}
|
43 |
+
else if ( get_option( 'webp-express-not-apache' ) ) {
|
44 |
+
delete_option( 'webp-express-not-apache');
|
45 |
+
printf(
|
46 |
+
'<div class="%1$s"><p>%2$s</p></div>',
|
47 |
+
esc_attr( 'notice notice-warning is-dismissible' ),
|
48 |
+
esc_html( __( 'You are not on Apache server. WebP Express has only been tested on Apache - continue at own risk (but please tell me if it works!). Your server is: ' . $_SERVER['SERVER_SOFTWARE'], 'webp-express' ) )
|
49 |
+
);
|
50 |
+
}
|
51 |
+
if ( get_option( 'webp-express-not-tested-on-litespeed' ) ) {
|
52 |
+
delete_option( 'webp-express-not-tested-on-litespeed');
|
53 |
+
printf(
|
54 |
+
'<div class="%1$s"><p>%2$s</p></div>',
|
55 |
+
esc_attr( 'notice notice-warning is-dismissible' ),
|
56 |
+
esc_html( __( 'You are on LiteSpeed server. WebP Express has only been tested sporadic on LiteSpeed... Continue at own risk', 'webp-express' ) )
|
57 |
+
);
|
58 |
+
return;
|
59 |
+
}
|
60 |
+
|
61 |
+
|
62 |
+
if ( get_option( 'webp-express-no-multisite' ) ) {
|
63 |
+
delete_option( 'webp-express-no-multisite');
|
64 |
+
printf(
|
65 |
+
'<div class="%1$s"><p>%2$s</p></div>',
|
66 |
+
esc_attr( 'notice notice-error is-dismissible' ),
|
67 |
+
esc_html( __( 'Sorry, WebP Express does not support multisite websites (yet). A donation might resolve the issue ;-)', 'webp-express' ) )
|
68 |
+
);
|
69 |
+
return;
|
70 |
+
}
|
71 |
+
|
72 |
+
if (get_option( 'webp-express-php-too-old' ) ) {
|
73 |
+
delete_option( 'webp-express-php-too-old');
|
74 |
+
printf(
|
75 |
+
'<div class="%1$s"><p>%2$s</p></div>',
|
76 |
+
esc_attr( 'notice notice-warning is-dismissible' ),
|
77 |
+
esc_html( sprintf(__( 'You are on a very old version of PHP (%s). WebP Express may not work as intended.', 'webp-express' ), phpversion() ) )
|
78 |
+
);
|
79 |
+
return;
|
80 |
+
}
|
81 |
+
|
82 |
+
if ( get_option( 'webp-express-failed-creating-upload-dir' ) ) {
|
83 |
+
delete_option( 'webp-express-failed-creating-upload-dir');
|
84 |
+
printf(
|
85 |
+
'<div class="%1$s"><p>%2$s</p></div>',
|
86 |
+
esc_attr( 'notice notice-error is-dismissible' ),
|
87 |
+
//esc_html( __( 'WebP Express could not create a subfolder in your upload folder. Check your file permissions', 'webp-express' ) )
|
88 |
+
'<b>WebP Express could not create a subfolder in your upload folder</b>. Check your file permissions. <a target="_blank" href="https://github.com/rosell-dk/webp-express/wiki/Error-messages-and-warnings#webp-express-could-not-create-a-subfolder-in-your-upload-folder">Click here</a> for more information.'
|
89 |
+
);
|
90 |
+
return;
|
91 |
+
}
|
92 |
+
|
93 |
+
/*
|
94 |
+
if ( get_option( 'webp-express-htaccess-not-writable' ) ) {
|
95 |
+
delete_option( 'webp-express-htaccess-not-writable');
|
96 |
+
printf(
|
97 |
+
'<div class="%1$s"><p>%2$s</p></div>',
|
98 |
+
esc_attr( 'notice notice-error is-dismissible' ),
|
99 |
+
'<b>.htaccess is not writable</b>. The plugin has been disabled. To fix this, make .htaccess writable and try activating the plugin again. <a target="_blank" href="https://github.com/rosell-dk/webp-express/wiki/Error-messages-and-warnings#htaccess-is-not-writable">Click here</a> for more information.'
|
100 |
+
//esc_html( __( '.htaccess is not writable. As WebP Express needs to write its redirection rules to .htaccess in order to function, the plugin has been disabled. To fix this, make .htaccess writable and try activating the plugin again. The file is located in the root of your wordpress installation.', 'webp-express' ) )
|
101 |
+
);
|
102 |
+
return;
|
103 |
+
}
|
104 |
+
|
105 |
+
if ( get_option( 'webp-express-failed-inserting-rules' ) ) {
|
106 |
+
delete_option( 'webp-express-failed-inserting-rules');
|
107 |
+
printf(
|
108 |
+
'<div class="%1$s"><p>%2$s</p></div>',
|
109 |
+
esc_attr( 'notice notice-error is-dismissible' ),
|
110 |
+
esc_html( __( 'WebP Express failed writing rules to .htaccess. The file is writable, but something went wrong writing to it anyway. More precicely, the Wordpress function "insert_with_markers" returned false. The .htaccess rules are needed for this plugin to function, and the plugin has therefore been deactivated.', 'webp-express' ) )
|
111 |
+
);
|
112 |
+
return;
|
113 |
+
}*/
|
114 |
+
|
115 |
+
if ( get_option( 'webp-express-failed-inserting-rules' ) ) {
|
116 |
+
delete_option( 'webp-express-failed-inserting-rules');
|
117 |
+
printf(
|
118 |
+
'<div class="%1$s"><p>%2$s</p></div>',
|
119 |
+
esc_attr( 'notice notice-error is-dismissible' ),
|
120 |
+
'<b>.htaccess is not writable</b>. To fix this, make .htaccess writable and try activating the plugin again. <a target="_blank" href="https://github.com/rosell-dk/webp-express/wiki/Error-messages-and-warnings#htaccess-is-not-writable">Click here</a> for more information.'
|
121 |
+
);
|
122 |
+
return;
|
123 |
+
}
|
124 |
+
|
125 |
+
printf(
|
126 |
+
'<div class="%1$s"><p>%2$s</p></div>',
|
127 |
+
esc_attr( 'notice notice-info is-dismissible' ),
|
128 |
+
'WebP Express was installed successfully. <a href="options-general.php?page=webp_express_settings_page">Configure it here</a>.'
|
129 |
+
);
|
130 |
+
|
131 |
+
printf(
|
132 |
+
'<div class="%1$s"><p>%2$s</p></div>',
|
133 |
+
esc_attr( 'notice notice-info is-dismissible' ),
|
134 |
+
esc_html( __( 'If you at some point change the upload directory or move Wordpress, you will have to disable and reenable WebPExpress', 'webp-express' ) )
|
135 |
+
);
|
136 |
+
}
|
137 |
+
});
|
138 |
+
|
139 |
+
|
140 |
+
|
141 |
+
?>
|
lib/options.php
ADDED
@@ -0,0 +1,466 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
// Maybe go away from using Settings API ?
|
4 |
+
// https://wpshout.com/wordpress-options-page/
|
5 |
+
|
6 |
+
|
7 |
+
include_once 'helpers.php';
|
8 |
+
|
9 |
+
add_action('admin_enqueue_scripts', function () {
|
10 |
+
// https://github.com/RubaXa/Sortable
|
11 |
+
|
12 |
+
wp_register_script('sortable', plugins_url('../js/sortable.min.js', __FILE__), [], '1.9.0');
|
13 |
+
wp_enqueue_script('sortable');
|
14 |
+
|
15 |
+
wp_register_script(
|
16 |
+
'webp-express-options-page',
|
17 |
+
plugins_url('../js/webp-express-options-page.js', __FILE__),
|
18 |
+
['sortable'],
|
19 |
+
'0.2.0'
|
20 |
+
);
|
21 |
+
wp_enqueue_script('webp-express-options-page');
|
22 |
+
|
23 |
+
wp_add_inline_script('webp-express-options-page', 'window.webpExpressPaths = ' . json_encode(WebPExpressHelpers::calculateUrlsAndPaths()) . ';');
|
24 |
+
//wp_add_inline_script('webp-express-options-page', 'window.converters = [{"converter":"imagick","id":"imagick"},{"converter":"cwebp","id":"cwebp"},{"converter":"gd","id":"gd"}];');
|
25 |
+
|
26 |
+
//wp_add_inline_script('webp-express-options-page', 'window.converters = [{"converter":"imagick","id":"imagick"},{"converter":"cwebp","id":"cwebp"},{"converter":"gd","id":"gd"}];');
|
27 |
+
// ,{"converter":"wpc","options":{"url":"http://","secret":"banana"},"id":"wpc"}
|
28 |
+
|
29 |
+
|
30 |
+
|
31 |
+
wp_register_style(
|
32 |
+
'webp-express-options-page-css',
|
33 |
+
plugins_url('../css/webp-express-options-page.css', __FILE__),
|
34 |
+
null,
|
35 |
+
'0.2.0'
|
36 |
+
);
|
37 |
+
wp_enqueue_style('webp-express-options-page-css');
|
38 |
+
|
39 |
+
add_thickbox();
|
40 |
+
});
|
41 |
+
|
42 |
+
|
43 |
+
|
44 |
+
add_action('admin_init', 'webp_express_option_group_init');
|
45 |
+
|
46 |
+
|
47 |
+
function webp_express_option_group_init()
|
48 |
+
{
|
49 |
+
/*
|
50 |
+
register_setting(
|
51 |
+
'webp_express_option_group', // A settings group name. Must exist prior to the register_setting call. This must match the group name in settings_fields()
|
52 |
+
'webp_express_options' //The name of an option to sanitize and save.
|
53 |
+
);*/
|
54 |
+
register_setting(
|
55 |
+
'webp_express_option_group', // A settings group name. Must exist prior to the register_setting call. This must match the group name in settings_fields()
|
56 |
+
'webp_express_max_quality', //The name of an option to sanitize and save.
|
57 |
+
[
|
58 |
+
'type' => 'integer',
|
59 |
+
'default' => '85',
|
60 |
+
'sanitize_callback' => 'sanitize_text_field',
|
61 |
+
]
|
62 |
+
);
|
63 |
+
register_setting(
|
64 |
+
'webp_express_option_group',
|
65 |
+
'webp_express_image_types_to_convert',
|
66 |
+
[
|
67 |
+
'type' => 'integer',
|
68 |
+
'default' => '3',
|
69 |
+
'sanitize_callback' => 'sanitize_text_field',
|
70 |
+
]
|
71 |
+
);
|
72 |
+
/*
|
73 |
+
register_setting(
|
74 |
+
'webp_express_option_group',
|
75 |
+
'webp_express_method',
|
76 |
+
[
|
77 |
+
'type' => 'integer',
|
78 |
+
'default' => '6',
|
79 |
+
'sanitize_callback' => 'sanitize_text_field',
|
80 |
+
]
|
81 |
+
);*/
|
82 |
+
register_setting(
|
83 |
+
'webp_express_option_group',
|
84 |
+
'webp_express_failure_response',
|
85 |
+
[
|
86 |
+
'type' => 'string',
|
87 |
+
'default' => 'original',
|
88 |
+
'sanitize_callback' => 'sanitize_text_field',
|
89 |
+
]
|
90 |
+
);
|
91 |
+
register_setting(
|
92 |
+
'webp_express_option_group',
|
93 |
+
'webp_express_converters',
|
94 |
+
[
|
95 |
+
'type' => 'string',
|
96 |
+
// TODO: test on new installation
|
97 |
+
'default' => '[{"converter":"cwebp","id":"cwebp"},{"converter":"wpc","id":"wpc"},{"converter":"gd","id":"gd"},{"converter":"imagick","id":"imagick"}]',
|
98 |
+
//'sanitize_callback' => 'sanitize_text_field',
|
99 |
+
]
|
100 |
+
);
|
101 |
+
|
102 |
+
|
103 |
+
add_settings_section('webp_express_conversion_options_section', 'Conversion options', function () {
|
104 |
+
//echo 'here you set conversion options';
|
105 |
+
}, 'webp_express_settings_page');
|
106 |
+
|
107 |
+
add_settings_field('webp_express_image_types_to_convert_id', 'Image types to convert', function () {
|
108 |
+
// bitmask
|
109 |
+
// 1: JPEGs
|
110 |
+
// 2: PNG's
|
111 |
+
// Converting only jpegs is thus "1"
|
112 |
+
// Converting both jpegs and pngs is (1+2) = 3
|
113 |
+
$imageTypes = get_option('webp_express_image_types_to_convert');
|
114 |
+
|
115 |
+
echo '<select name="webp_express_image_types_to_convert">';
|
116 |
+
echo '<option value="0"' . ($imageTypes == 0 ? ' selected' : '') . '>Do not convert any images!</option>';
|
117 |
+
echo '<option value="1"' . ($imageTypes == 1 ? ' selected' : '') . '>Only convert jpegs</option>';
|
118 |
+
echo '<option value="3"' . ($imageTypes == 3 ? ' selected' : '') . '>Convert both jpegs and pngs</option>';
|
119 |
+
echo '</select>';
|
120 |
+
|
121 |
+
//echo '<input type="checkbox" ' . ($types == 1 ? ' checked=checked' : '') . '>';
|
122 |
+
|
123 |
+
}, 'webp_express_settings_page', 'webp_express_conversion_options_section');
|
124 |
+
|
125 |
+
/*
|
126 |
+
add_settings_field('webp_express_method_id', 'Method (0-6)', function () {
|
127 |
+
$method = get_option('webp_express_method');
|
128 |
+
echo "<input type='text' name='webp_express_method' value='" . $method . "' />";
|
129 |
+
echo '<p>When higher values are used, the encoder will spend more time inspecting additional encoding possibilities and decide on the quality gain. Supported by cwebp, wpc and imagick</p>';
|
130 |
+
}, 'webp_express_settings_page', 'webp_express_conversion_options_section');
|
131 |
+
*/
|
132 |
+
|
133 |
+
add_settings_field('webp_express_failure_response', 'Response on failure', function () {
|
134 |
+
$failureResponse = get_option('webp_express_failure_response');
|
135 |
+
echo '<select name="webp_express_failure_response">';
|
136 |
+
echo '<option value="original"' . ($failureResponse == 'original' ? ' selected' : '') . '>Original image</option>';
|
137 |
+
echo '<option value="404"' . ($failureResponse == '404' ? ' selected' : '') . '>404</option>';
|
138 |
+
echo '<option value="report"' . ($failureResponse == 'report' ? ' selected' : '') . '>Error report (in plain text)</option>';
|
139 |
+
echo '<option value="report-as-image"' . ($failureResponse == 'report-as-image' ? ' selected' : '') . '>Error report as image</option>';
|
140 |
+
echo '</select>';
|
141 |
+
echo '<p>Determines what the converter should serve, in case the image conversion should fail. For production servers, recommended value is "Original image". For development servers, choose anything you like, but that</p>';
|
142 |
+
}, 'webp_express_settings_page', 'webp_express_conversion_options_section');
|
143 |
+
|
144 |
+
add_settings_field('webp_express_max_quality_id', 'Max quality (0-100)', function () {
|
145 |
+
echo "<input type='text' name='webp_express_max_quality' value='" . get_option('webp_express_max_quality') . "' />";
|
146 |
+
echo '<p>Converted jpeg images will get same quality as original, but not more than this setting. 85 is recommended for most websites.</p>';
|
147 |
+
}, 'webp_express_settings_page', 'webp_express_conversion_options_section');
|
148 |
+
|
149 |
+
|
150 |
+
/*
|
151 |
+
public static $CONVERTED_IMAGE = 1;
|
152 |
+
public static $ORIGINAL = -1;
|
153 |
+
public static $HTTP_404 = -2;
|
154 |
+
public static $REPORT_AS_IMAGE = -3;
|
155 |
+
public static $REPORT = -4;*/
|
156 |
+
|
157 |
+
add_settings_field('webp_express_converters', '', function () {
|
158 |
+
$converters = get_option('webp_express_converters');
|
159 |
+
echo '<script>window.converters = ' . get_option('webp_express_converters') . '</script>';
|
160 |
+
|
161 |
+
echo "<input type='text' name='webp_express_converters' value='' />";
|
162 |
+
}, 'webp_express_settings_page', 'webp_express_conversion_options_section');
|
163 |
+
}
|
164 |
+
|
165 |
+
|
166 |
+
/* Settings Page Content */
|
167 |
+
function webp_express_settings_page_content()
|
168 |
+
{
|
169 |
+
if (!current_user_can('manage_options')) {
|
170 |
+
wp_die(__('You do not have sufficient permissions to access this page.', 'yasr'));
|
171 |
+
}
|
172 |
+
?>
|
173 |
+
<div class="wrap">
|
174 |
+
<h2>WebP Express Settings</h2>
|
175 |
+
|
176 |
+
<form action="options.php" method="post">
|
177 |
+
<?php
|
178 |
+
settings_fields('webp_express_option_group');
|
179 |
+
do_settings_sections('webp_express_settings_page');
|
180 |
+
|
181 |
+
|
182 |
+
//echo '<pre>' . print_r(WebPExpressHelpers::calculateUrlsAndPaths(), true) . '</pre>';
|
183 |
+
|
184 |
+
$localConverters = ['cwebp', 'imagick', 'gd'];
|
185 |
+
|
186 |
+
/*
|
187 |
+
$testResult = WebPExpressHelpers::testConverters($localConverters);
|
188 |
+
//print_r($testResult);
|
189 |
+
|
190 |
+
if ($testResult['numOperationalConverters'] == 0) {
|
191 |
+
echo 'Unfortunately, your server is currently not able to convert to webp files by itself. You will need to set up a cloud converter.<br><br>';
|
192 |
+
foreach ($testResult['results'] as $result) {
|
193 |
+
echo $result['converter'] . ':' . $result['message'] . '<br>';
|
194 |
+
}
|
195 |
+
} else {
|
196 |
+
//echo 'Your server is able to convert webp files by itself.';
|
197 |
+
}
|
198 |
+
if ($testResult['numOperationalConverters'] == 1) {
|
199 |
+
//
|
200 |
+
}
|
201 |
+
*/
|
202 |
+
$extraConverters = [
|
203 |
+
[
|
204 |
+
'converter' => 'ewww',
|
205 |
+
'options' => array(
|
206 |
+
'key' => 'your api key here',
|
207 |
+
),
|
208 |
+
]
|
209 |
+
];
|
210 |
+
|
211 |
+
$converters = [
|
212 |
+
[
|
213 |
+
'converter' => 'cwebp',
|
214 |
+
],
|
215 |
+
[
|
216 |
+
'converter' => 'imagick',
|
217 |
+
],
|
218 |
+
[
|
219 |
+
'converter' => 'gd',
|
220 |
+
],
|
221 |
+
[
|
222 |
+
'converter' => 'ewww',
|
223 |
+
'options' => [
|
224 |
+
'key' => 'your api key here',
|
225 |
+
],
|
226 |
+
]
|
227 |
+
];
|
228 |
+
|
229 |
+
/*
|
230 |
+
http://php.net/manual/en/function.set-include-path.php
|
231 |
+
|
232 |
+
|
233 |
+
//exec('/usr/sbin/getsebool -a', $output6, $returnCode5); // ok
|
234 |
+
//echo 'All se bools: ' . print_r($output6, true) . '. Return code:' . $returnCode5;
|
235 |
+
*/
|
236 |
+
|
237 |
+
|
238 |
+
|
239 |
+
|
240 |
+
|
241 |
+
echo '<h2>Converters</h2>';
|
242 |
+
$dragIcon = '<svg version="1.0" xmlns="http://www.w3.org/2000/svg" width="17px" height="17px" viewBox="0 0 100.000000 100.000000" preserveAspectRatio="xMidYMid meet"><g transform="translate(0.000000,100.000000) scale(0.100000,-0.100000)" fill="#444444" stroke="none"><path d="M415 920 l-80 -80 165 0 165 0 -80 80 c-44 44 -82 80 -85 80 -3 0 -41 -36 -85 -80z"/><path d="M0 695 l0 -45 500 0 500 0 0 45 0 45 -500 0 -500 0 0 -45z"/><path d="M0 500 l0 -40 500 0 500 0 0 40 0 40 -500 0 -500 0 0 -40z"/><path d="M0 305 l0 -45 500 0 500 0 0 45 0 45 -500 0 -500 0 0 -45z"/><path d="M418 78 l82 -83 82 83 83 82 -165 0 -165 0 83 -82z"/></g></svg>';
|
243 |
+
|
244 |
+
echo '<p><i>Drag to reorder. The converter on top will be used. Should it fail, the next will be used, etc</i></p>';
|
245 |
+
// https://github.com/RubaXa/Sortable
|
246 |
+
|
247 |
+
// Empty list of converters. The list will be populated by the javascript
|
248 |
+
echo '<ul id="converters"></ul>';
|
249 |
+
?>
|
250 |
+
<div id="cwebp" style="display:none;">
|
251 |
+
<div class="cwebp converter-options">
|
252 |
+
<h3>cwebp</h3>
|
253 |
+
<div class="info">
|
254 |
+
cwebp works by executing the cwebp binary from Google. This should be your first choice.
|
255 |
+
Its best in terms of quality, speed and options. The only catch is that it requires the exec function to be enabled,
|
256 |
+
and that the webserver user is allowed to execute the cwebp binary (either at known system locations, or one of the precompiled binaries,
|
257 |
+
that comes with this library). If you are on a shared host that doesn't allow that, the second best choice would probably be the wpc cloud converter.
|
258 |
+
</div>
|
259 |
+
<h3>cweb options</h3>
|
260 |
+
<div>
|
261 |
+
<label for="cwebp_use_nice">Use nice</label>
|
262 |
+
<input type="checkbox" id="cwebp_use_nice">
|
263 |
+
<br>Enabling "use nice" saves system resources at the cost of slightly slower conversion
|
264 |
+
|
265 |
+
</div>
|
266 |
+
<br>
|
267 |
+
<button onclick="updateConverterOptions()" class="button button-primary" type="button">Update</button>
|
268 |
+
<!-- <a href="javascript: tb_remove();">close</a> -->
|
269 |
+
</div>
|
270 |
+
</div>
|
271 |
+
<div id="gd" style="display:none;">
|
272 |
+
<div class="ewww converter-options">
|
273 |
+
<h3>Gd</h3>
|
274 |
+
<p>
|
275 |
+
The gd converter uses the Gd extension to do the conversion. It is per default placed below the cloud converters for two reasons.
|
276 |
+
Firstly, it does not seem to produce quite as good quality as cwebp.
|
277 |
+
Secondly, it provides no conversion options, besides quality.
|
278 |
+
The Gd extension is pretty common, so the main feature of this converter is that it <i>may</i> work out of the box.
|
279 |
+
This is in contrast to the cloud converters, which requires that the user does some setup.
|
280 |
+
</p>
|
281 |
+
<h3>Gd options</h3>
|
282 |
+
<div class="info">
|
283 |
+
Gd neither supports copying metadata nor exposes any WebP options. Lacking the option to set lossless encoding results in poor encoding of PNGs - the filesize is generally much larger than the original. For this reason, the converter defaults to skip PNG's.
|
284 |
+
</div>
|
285 |
+
<div>
|
286 |
+
<label for="gd_skip_pngs">Skip PNGs</label>
|
287 |
+
<input type="checkbox" id="gd_skip_pngs">
|
288 |
+
</div>
|
289 |
+
<br>
|
290 |
+
<button onclick="updateConverterOptions()" class="button button-primary" type="button">Update</button>
|
291 |
+
<!-- <a href="javascript: tb_remove();">close</a> -->
|
292 |
+
</div>
|
293 |
+
</div>
|
294 |
+
<div id="imagick" style="display:none;">
|
295 |
+
<div class="imagick converter-options">
|
296 |
+
<h3>Imagick</h3>
|
297 |
+
<p>
|
298 |
+
imagick would be your last choice. For some reason it produces conversions that are only marginally better than the originals.
|
299 |
+
See <a href="https://github.com/rosell-dk/webp-convert/issues/43" target="_blank">this issue</a>. But it is fast.
|
300 |
+
</p>
|
301 |
+
<h3>Imagick options</h3>
|
302 |
+
<div class="info">
|
303 |
+
imagick has no extra options.
|
304 |
+
</div>
|
305 |
+
<br>
|
306 |
+
<!--
|
307 |
+
<button onclick="updateConverterOptions()" class="button button-primary" type="button">Update</button>
|
308 |
+
-->
|
309 |
+
<!-- <a href="javascript: tb_remove();">close</a> -->
|
310 |
+
</div>
|
311 |
+
</div>
|
312 |
+
<div id="ewww" style="display:none;">
|
313 |
+
<div class="ewww converter-options">
|
314 |
+
<h3>Ewww</h3>
|
315 |
+
<p>
|
316 |
+
<a href="https://ewww.io/" target="_blank">ewww</a> is a cloud service. It is a decent alternative for those who don't have the technical know-how to install wpc.
|
317 |
+
ewww is using cwebp to do the conversion, so quality is great.
|
318 |
+
ewww however only provides one conversion option (quality), and it is not free.
|
319 |
+
But very cheap. Like in almost free.
|
320 |
+
</p>
|
321 |
+
<h3>Ewww options</h3>
|
322 |
+
<div>
|
323 |
+
<label for="ewww_key">Key</label>
|
324 |
+
<input type="text" id="ewww_key" placeholder="Your API key here">
|
325 |
+
</div>
|
326 |
+
<br>
|
327 |
+
<h4>Fallback (optional)</h4>
|
328 |
+
<div>
|
329 |
+
<label for="ewww_key_2">key</label>
|
330 |
+
<input type="text" id="ewww_key_2" placeholder="In case the first one expires...">
|
331 |
+
</div>
|
332 |
+
<br>
|
333 |
+
<button onclick="updateConverterOptions()" class="button button-primary" type="button">Update</button>
|
334 |
+
<!-- <a href="javascript: tb_remove();">close</a> -->
|
335 |
+
</div>
|
336 |
+
</div>
|
337 |
+
<div id="wpc" style="display:none;">
|
338 |
+
<div class="wpc converter-options">
|
339 |
+
<h3>WebPConvert Cloud Service</h3>
|
340 |
+
wpc is an open source cloud converter based on <a href="https://github.com/rosell-dk/webp-convert" target="_blank">WebPConvert</a>
|
341 |
+
(this plugin also happens to be based on WebPConvert).
|
342 |
+
Conversions will of course be slower than cwebp, as images need to go back and forth to the cloud converter.
|
343 |
+
As images usually just needs to be converted once, the slower conversion
|
344 |
+
speed is probably acceptable. The conversion quality and options of wpc matches cwebp.
|
345 |
+
The only catch is that you will need to install the WPC library on a server (or have someone do it for you).
|
346 |
+
<a href="https://github.com/rosell-dk/webp-convert-cloud-service" target="blank">Visit WPC on github</a>.
|
347 |
+
If this is a problem, we suggest you turn to ewww.
|
348 |
+
(PS: A Wordpress plugin is planned, making it easier to set up a WPC instance. Or perhaps the functionality will even be part of this plugin)
|
349 |
+
|
350 |
+
<h3>Options for WebPConvert Cloud Service</h3>
|
351 |
+
<div>
|
352 |
+
<label for="wpc_url">URL</label>
|
353 |
+
<input type="text" id="wpc_url" placeholder="Url to your WPC instance">
|
354 |
+
</div>
|
355 |
+
|
356 |
+
<div>
|
357 |
+
<label for="wpc_secret">Secret</label>
|
358 |
+
<input type="text" id="wpc_secret" placeholder="Secret (must match secret on server side)">
|
359 |
+
</div>
|
360 |
+
<br>
|
361 |
+
<h4>Fallback (optional)</h4>
|
362 |
+
<p>In case the first is down, the fallback will be used.</p>
|
363 |
+
<div>
|
364 |
+
<label for="wpc_url_2">URL</label>
|
365 |
+
<input type="text" id="wpc_url_2" placeholder="Url to your other WPC instance">
|
366 |
+
</div>
|
367 |
+
<div>
|
368 |
+
<label for="wpc_secret_2">Secret</label>
|
369 |
+
<input type="text" id="wpc_secret_2" placeholder="Secret (must match secret on server side)">
|
370 |
+
</div>
|
371 |
+
<br>
|
372 |
+
<button onclick="updateConverterOptions()" class="button button-primary" type="button">Update</button>
|
373 |
+
</div>
|
374 |
+
</div>
|
375 |
+
<?php
|
376 |
+
//print_r($urls);
|
377 |
+
//echo $urls['urls']['webpExpressRoot'];
|
378 |
+
if (isset($_SERVER['HTTP_ACCEPT']) && (strpos($_SERVER['HTTP_ACCEPT'], 'image/webp') !== false )) {
|
379 |
+
echo 'Your browser supports webp... So you can test if everything works (including the redirect magic) - using these links:<br>';
|
380 |
+
$webpExpressRoot = WebPExpressHelpers::calculateUrlsAndPaths()['urls']['webpExpressRoot'];
|
381 |
+
echo '<a href="' . $webpExpressRoot . '/test/test.jpg" target="_blank">Convert test image</a><br>';
|
382 |
+
echo '<a href="' . $webpExpressRoot . '/test/test.jpg?debug" target="_blank">Convert test image (show debug)</a><br>';
|
383 |
+
}
|
384 |
+
?>
|
385 |
+
|
386 |
+
<!--
|
387 |
+
<div id="add-cloud-converter-id" style="display:none;">
|
388 |
+
<p>
|
389 |
+
Select cloud converter to add:
|
390 |
+
|
391 |
+
<button onclick="addConverter('ewww')" class="button button-primary" type="button">Add ewww converter</button>
|
392 |
+
</p>
|
393 |
+
</div>
|
394 |
+
<button class="button button-secondary" onclick="addConverterClick()" type="button">Add cloud converter</button>
|
395 |
+
-->
|
396 |
+
<?php
|
397 |
+
|
398 |
+
|
399 |
+
submit_button('Save settings');
|
400 |
+
?>
|
401 |
+
</form>
|
402 |
+
</div>
|
403 |
+
|
404 |
+
<?php
|
405 |
+
}
|
406 |
+
|
407 |
+
add_action('updated_option', function($option_name, $old_value, $value) {
|
408 |
+
switch ($option_name) {
|
409 |
+
case 'webp_express_max_quality':
|
410 |
+
//case 'webp_express_method':
|
411 |
+
case 'webp_express_converters':
|
412 |
+
case 'webp_express_image_types_to_convert':
|
413 |
+
case 'webp_express_failure_response':
|
414 |
+
//update_option('webp-express-htaccess-needs-updating', true, false);
|
415 |
+
|
416 |
+
$rules = WebPExpressHelpers::generateHTAccessRules();
|
417 |
+
WebPExpressHelpers::insertHTAccessRules($rules);
|
418 |
+
|
419 |
+
break;
|
420 |
+
}
|
421 |
+
}, 10, 3);
|
422 |
+
|
423 |
+
|
424 |
+
|
425 |
+
//End webp_express_settings_page_content
|
426 |
+
|
427 |
+
//include( plugin_dir_path( __FILE__ ) . 'lib/helpers.php');
|
428 |
+
|
429 |
+
//echo '<pre>rules:' . WebPExpressHelpers::generateHTAccessRules() . '</pre>';
|
430 |
+
|
431 |
+
/*
|
432 |
+
add_action('admin_menu', function () {
|
433 |
+
add_options_page('WebP Express', 'WebP Express', 'manage_options', 'webp-express', function () {
|
434 |
+
include(plugin_dir_path(__FILE__) . 'lib/options.php');
|
435 |
+
});
|
436 |
+
});
|
437 |
+
|
438 |
+
function d1() {
|
439 |
+
echo '<p>Main description of this section here.</p>';
|
440 |
+
}
|
441 |
+
function d2() {
|
442 |
+
$options = get_option('options');
|
443 |
+
echo "<input id='plugin_text_string' name='plugin_options[text_string]' size='40' type='text' value='{$options['text_string']}' />";
|
444 |
+
}
|
445 |
+
function plugin_options_validate($input) {
|
446 |
+
$newinput['text_string'] = trim($input['text_string']);
|
447 |
+
if (!preg_match('/^[a-z0-9]{32}$/i', $newinput['text_string'])) {
|
448 |
+
$newinput['text_string'] = '';
|
449 |
+
}
|
450 |
+
return $newinput;
|
451 |
+
}
|
452 |
+
|
453 |
+
add_action('admin_init', function () {
|
454 |
+
register_setting('general', 'quality', [
|
455 |
+
'type' => 'string',
|
456 |
+
'default' => '85'
|
457 |
+
]);
|
458 |
+
add_settings_field('plugin_text_string', 'Plugin Text Input', function () {
|
459 |
+
echo 'hello...';
|
460 |
+
}, 'webp-express');
|
461 |
+
|
462 |
+
//register_setting('webp_express_options', 'options', 'plugin_options_validate');
|
463 |
+
//add_settings_section('webp_express_main', 'Main Settings', d1, 'webp_express');
|
464 |
+
//add_settings_field('plugin_text_string', 'Plugin Text Input', d2, 'webp_express', 'webp_express_main');
|
465 |
+
});
|
466 |
+
*/
|
test-run.php
ADDED
@@ -0,0 +1,254 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
//require 'webp-on-demand/vendor/autoload.php';
|
4 |
+
|
5 |
+
|
6 |
+
//require 'vendor/webp-convert-and-serve/autoload.php';
|
7 |
+
require 'vendor/webp-convert/autoload.php';
|
8 |
+
|
9 |
+
//use WebPConvertAndServe\WebPConvertAndServe;
|
10 |
+
use WebPConvert\WebPConvert;
|
11 |
+
use WebPConvert\Converters\ConverterHelper;
|
12 |
+
|
13 |
+
// TODO:
|
14 |
+
// Much of this file could be moved into the libraries.
|
15 |
+
// Ie:
|
16 |
+
// - Report (such as "trying gd", "successfully...", "file size (original)") could be part of WebPConvertAndServe
|
17 |
+
// ($REPORT_AS_IMAGE and $REPORT actions could show complete report, and convertAndReport too)
|
18 |
+
// - or even be part of WebPConvert - ie the log could be returned in a variable passed by reference.
|
19 |
+
//
|
20 |
+
|
21 |
+
$source = $_GET['source'];
|
22 |
+
$destination = $_GET['destination'];
|
23 |
+
$converter = $_GET['converter'];
|
24 |
+
|
25 |
+
if (isset($_GET['max-quality'])) {
|
26 |
+
$options['max-quality'] = intval($_GET['max-quality']);
|
27 |
+
}
|
28 |
+
|
29 |
+
if (isset($_GET['method'])) {
|
30 |
+
$options['method'] = intval($_GET['method']);
|
31 |
+
}
|
32 |
+
|
33 |
+
/*
|
34 |
+
switch ($converter) {
|
35 |
+
case 'ewww':
|
36 |
+
if (isset($_GET['key'])) {
|
37 |
+
$options['key'] = $_GET['key'];
|
38 |
+
}
|
39 |
+
break;
|
40 |
+
case 'cwebp':
|
41 |
+
if (isset($_GET['use-nice'])) {
|
42 |
+
$options['use-nice'] = boolval($_GET['use-nice'] == 'true');
|
43 |
+
}
|
44 |
+
break;
|
45 |
+
case 'gd':
|
46 |
+
if (isset($_GET['skip-pngs'])) {
|
47 |
+
$options['skip-pngs'] = boolval($_GET['skip-pngs'] == 'true');
|
48 |
+
}
|
49 |
+
break;
|
50 |
+
}*/
|
51 |
+
|
52 |
+
$converterClassName = 'WebPConvert\\Converters\\' . ucfirst($converter);
|
53 |
+
$availOptions = array_column($converterClassName::$extraOptions, 'type', 'name');
|
54 |
+
//print_r($availOptions);
|
55 |
+
|
56 |
+
$hasFallback = false;
|
57 |
+
$options2 = [];
|
58 |
+
foreach ($availOptions as $optionName => $optionType) {
|
59 |
+
if (isset($_GET[$optionName . '-2'])) {
|
60 |
+
if ($_GET[$optionName . '-2'] != '') {
|
61 |
+
$hasFallback = true;
|
62 |
+
$options2 = $options;
|
63 |
+
// echo 'value:' . $_GET[$optionName . '-2'];
|
64 |
+
break;
|
65 |
+
}
|
66 |
+
}
|
67 |
+
}
|
68 |
+
|
69 |
+
foreach ($availOptions as $optionName => $optionType) {
|
70 |
+
switch ($optionType) {
|
71 |
+
case 'string':
|
72 |
+
if (isset($_GET[$optionName])) {
|
73 |
+
$options[$optionName] = $_GET[$optionName];
|
74 |
+
}
|
75 |
+
if (isset($_GET[$optionName. '-2'])) {
|
76 |
+
$options2[$optionName] = $_GET[$optionName . '-2'];
|
77 |
+
} else {
|
78 |
+
if ($hasFallback) {
|
79 |
+
$options2[$optionName] = $options[$optionName];
|
80 |
+
}
|
81 |
+
}
|
82 |
+
break;
|
83 |
+
case 'boolean':
|
84 |
+
if (isset($_GET[$optionName])) {
|
85 |
+
$options[$optionName] = ($_GET[$optionName] == 'true');
|
86 |
+
}
|
87 |
+
break;
|
88 |
+
}
|
89 |
+
}
|
90 |
+
|
91 |
+
//echo '<pre>' . print_r($options, true) . '</pre>';
|
92 |
+
//echo '<pre>' . print_r($options2, true) . '</pre>';
|
93 |
+
|
94 |
+
//echo '';
|
95 |
+
?>
|
96 |
+
<html>
|
97 |
+
<head>
|
98 |
+
<style>
|
99 |
+
body {
|
100 |
+
padding:10px;
|
101 |
+
font-size: 17px;
|
102 |
+
}
|
103 |
+
p {
|
104 |
+
margin-top: 0;
|
105 |
+
}
|
106 |
+
label {
|
107 |
+
font-style: italic;
|
108 |
+
}
|
109 |
+
p.error-msg {
|
110 |
+
/*font-size: 20px;*/
|
111 |
+
}
|
112 |
+
h3 {color: red}
|
113 |
+
</style>
|
114 |
+
</head>
|
115 |
+
<body style="">
|
116 |
+
|
117 |
+
<?php
|
118 |
+
//echo '<p>source: ' . $source . '</p>';
|
119 |
+
//echo '<p>destination: ' . $destination . '</p>';
|
120 |
+
//echo '<p>converter: ' . $converter . '</p>';
|
121 |
+
//echo '</body></html>';
|
122 |
+
|
123 |
+
//WebPConvertAndServe::convertAndReport($source, $destination, $options);
|
124 |
+
|
125 |
+
function testRun($converter, $source, $destination, $options) {
|
126 |
+
$beginTime = microtime(true);
|
127 |
+
|
128 |
+
try {
|
129 |
+
ConverterHelper::runConverter($converter, $source, $destination, $options);
|
130 |
+
} catch (\WebPConvert\Exceptions\WebPConvertBaseException $e) {
|
131 |
+
$failure = $e->description;
|
132 |
+
$msg = $e->getMessage();
|
133 |
+
} catch (\Exception $e) {
|
134 |
+
$failure = 'Unancipated failure';
|
135 |
+
$msg = $e->getMessage();
|
136 |
+
}
|
137 |
+
|
138 |
+
$endTime = microtime(true);
|
139 |
+
$duration = $endTime - $beginTime;
|
140 |
+
|
141 |
+
if (isset($msg)) {
|
142 |
+
echo '<h3 class="error">Test conversion failed (in ' . round($duration * 1000) . ' ms)</h3>';
|
143 |
+
echo '<label>Problem:</label>';
|
144 |
+
echo '<p class="failure">' . $failure . '</p>';
|
145 |
+
echo '<label>Details:</label>';
|
146 |
+
echo '<p class="error-msg">' . $msg . '</p>';
|
147 |
+
} else {
|
148 |
+
echo '<p>Successfully converted test image in ' . round($duration * 1000) . ' ms</p>';
|
149 |
+
|
150 |
+
if (isset($_SERVER['HTTP_ACCEPT']) && (strpos($_SERVER['HTTP_ACCEPT'], 'image/webp') !== false )) {
|
151 |
+
echo '<img src="' . $_GET['destinationUrl'] . '" width=48%><br><br>';
|
152 |
+
}
|
153 |
+
if (filesize($source) < 10000) {
|
154 |
+
echo 'file size (original): ' . round(filesize($source)) . ' bytes<br>';
|
155 |
+
echo 'file size (converted): ' . round(filesize($destination)) . ' bytes<br>';
|
156 |
+
}
|
157 |
+
else {
|
158 |
+
echo 'file size (original): ' . round(filesize($source)/1000) . ' kb<br>';
|
159 |
+
echo 'file size (converted): ' . round(filesize($destination)/1000) . ' kb<br>';
|
160 |
+
}
|
161 |
+
}
|
162 |
+
}
|
163 |
+
|
164 |
+
testRun($converter, $source, $destination, $options);
|
165 |
+
|
166 |
+
if ($hasFallback) {
|
167 |
+
echo '<h2>Testing fallback</h2>';
|
168 |
+
testRun($converter, $source, $destination, $options2);
|
169 |
+
}
|
170 |
+
|
171 |
+
|
172 |
+
|
173 |
+
|
174 |
+
/*
|
175 |
+
$className = 'WebPConvert\\Converters\\' . ucfirst($converter);
|
176 |
+
|
177 |
+
if (!is_callable([$className, 'convert'])) {
|
178 |
+
echo 'Converter does not appear to exist!';
|
179 |
+
exit;
|
180 |
+
}
|
181 |
+
|
182 |
+
try {
|
183 |
+
call_user_func(
|
184 |
+
[$className, 'convert'],
|
185 |
+
$source,
|
186 |
+
$destination,
|
187 |
+
$options
|
188 |
+
);
|
189 |
+
} catch (\WebPConvert\Converters\Exceptions\ConverterNotOperationalException $e) {
|
190 |
+
// The converter is not operational.
|
191 |
+
$failure = 'The converter is not operational';
|
192 |
+
|
193 |
+
// TODO: We should show link to install instructions for the specific converter (WIKI)
|
194 |
+
|
195 |
+
$msg = $e->getMessage();
|
196 |
+
} catch (\WebPConvert\Converters\Exceptions\ConverterFailedException $e) {
|
197 |
+
$failure = 'The converter failed converting, although requirements seemed to be met';
|
198 |
+
$msg = $e->getMessage();
|
199 |
+
} catch (\WebPConvert\Converters\Exceptions\ConversionDeclinedException $e) {
|
200 |
+
$failure = 'The converter declined converting';
|
201 |
+
$msg = $e->getMessage();
|
202 |
+
} catch (\WebPConvert\Exceptions\InvalidFileExtensionException $e) {
|
203 |
+
$failure = 'The converter does not accept the file extension';
|
204 |
+
$msg = $e->getMessage();
|
205 |
+
} catch (\WebPConvert\Exceptions\TargetNotFoundException $e) {
|
206 |
+
$failure = 'The converter could not locate source file';
|
207 |
+
$msg = $e->getMessage();
|
208 |
+
} catch (\WebPConvert\Exceptions\CreateDestinationFolderException $e) {
|
209 |
+
$failure = 'The converter could not create destination folder. Check file permisions!';
|
210 |
+
$msg = $e->getMessage();
|
211 |
+
} catch (\WebPConvert\Exceptions\CreateDestinationFileException $e) {
|
212 |
+
$failure = 'The converter could not create destination file. Check file permisions!';
|
213 |
+
$msg = $e->getMessage();
|
214 |
+
} catch (\Exception $e) {
|
215 |
+
$failure = 'Unexpected failure';
|
216 |
+
$msg = $e->getMessage();
|
217 |
+
}
|
218 |
+
*/
|
219 |
+
|
220 |
+
|
221 |
+
|
222 |
+
|
223 |
+
/*
|
224 |
+
try {
|
225 |
+
$options = [
|
226 |
+
'converters' => [$converter]
|
227 |
+
];
|
228 |
+
$success = WebPConvert::convert($source, $destination, $options);
|
229 |
+
} catch (\Exception $e) {
|
230 |
+
$success = false;
|
231 |
+
$msg = $e->getMessage();
|
232 |
+
}
|
233 |
+
|
234 |
+
if ($success) {
|
235 |
+
$endTime = microtime(true);
|
236 |
+
|
237 |
+
$duration = $endTime - $beginTime;
|
238 |
+
echo '<p>Successfully converted test image in ' . round($duration * 1000) . ' ms</p>';
|
239 |
+
|
240 |
+
|
241 |
+
if (isset($_SERVER['HTTP_ACCEPT']) && (strpos($_SERVER['HTTP_ACCEPT'], 'image/webp') !== false )) {
|
242 |
+
echo '<img src="' . $_GET['destinationUrl'] . '" width=50%>';
|
243 |
+
}
|
244 |
+
} else {
|
245 |
+
echo 'Converter failed ';
|
246 |
+
echo $msg;
|
247 |
+
}
|
248 |
+
*/
|
249 |
+
/*
|
250 |
+
$status = WebPOnDemand::serve(__DIR__);
|
251 |
+
if ($status < 0) {
|
252 |
+
// Conversion failed.
|
253 |
+
// you could message your application about the problem here...
|
254 |
+
}*/
|
test/focus.jpg
ADDED
Binary file
|
test/test.jpg
ADDED
Binary file
|
vendor/webp-convert-and-serve/WebPConvertAndServe.php
ADDED
@@ -0,0 +1,196 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
namespace WebPConvertAndServe;
|
3 |
+
|
4 |
+
use WebPConvert\WebPConvert;
|
5 |
+
use WebPConvertAndServe\PathHelper;
|
6 |
+
use WebPConvert\Converters\ConverterHelper;
|
7 |
+
//use WebPConvert\Loggers\EchoLogger;
|
8 |
+
|
9 |
+
class WebPConvertAndServe
|
10 |
+
{
|
11 |
+
public static $CONVERTED_IMAGE = 1;
|
12 |
+
public static $ORIGINAL = -1;
|
13 |
+
public static $HTTP_404 = -2;
|
14 |
+
public static $REPORT_AS_IMAGE = -3;
|
15 |
+
public static $REPORT = -4;
|
16 |
+
|
17 |
+
private static function serve404()
|
18 |
+
{
|
19 |
+
$protocol = isset($_SERVER["SERVER_PROTOCOL"]) ? $_SERVER["SERVER_PROTOCOL"] : 'HTTP/1.0';
|
20 |
+
header($protocol . " 404 Not Found");
|
21 |
+
}
|
22 |
+
|
23 |
+
private static function serveOriginal($source)
|
24 |
+
{
|
25 |
+
// Prevent caching image
|
26 |
+
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
|
27 |
+
header("Cache-Control: post-check=0, pre-check=0", false);
|
28 |
+
header("Pragma: no-cache");
|
29 |
+
|
30 |
+
$arr = explode('.', $source);
|
31 |
+
$ext = array_pop($arr);
|
32 |
+
switch (strtolower($ext)) {
|
33 |
+
case 'jpg':
|
34 |
+
case 'jpeg':
|
35 |
+
header('Content-type: image/jpeg');
|
36 |
+
break;
|
37 |
+
case 'png':
|
38 |
+
header('Content-type: image/png');
|
39 |
+
break;
|
40 |
+
}
|
41 |
+
readfile($source);
|
42 |
+
}
|
43 |
+
|
44 |
+
private static function serveErrorMessageImage($msg)
|
45 |
+
{
|
46 |
+
// Generate image containing error message
|
47 |
+
header('Content-type: image/gif');
|
48 |
+
|
49 |
+
// Prevent caching image
|
50 |
+
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
|
51 |
+
header("Cache-Control: post-check=0, pre-check=0", false);
|
52 |
+
header("Pragma: no-cache");
|
53 |
+
|
54 |
+
$image = imagecreatetruecolor(620, 200);
|
55 |
+
imagestring($image, 1, 5, 5, $msg, imagecolorallocate($image, 233, 214, 291));
|
56 |
+
// echo imagewebp($image);
|
57 |
+
echo imagegif($image);
|
58 |
+
imagedestroy($image);
|
59 |
+
}
|
60 |
+
|
61 |
+
|
62 |
+
public static function convertAndServeImage($source, $destination, $options, $failAction, $criticalFailAction, $debug = false)
|
63 |
+
{
|
64 |
+
/*
|
65 |
+
if ($debug) {
|
66 |
+
error_reporting(E_ALL);
|
67 |
+
ini_set('display_errors', 'On');
|
68 |
+
} else {
|
69 |
+
ini_set('display_errors', 'Off');
|
70 |
+
}*/
|
71 |
+
|
72 |
+
$criticalFail = false;
|
73 |
+
|
74 |
+
$success = false;
|
75 |
+
|
76 |
+
$echoLogger = null;
|
77 |
+
if (class_exists('WebPConvert\Loggers\EchoLogger')) {
|
78 |
+
$echoLogger = new \WebPConvert\Loggers\EchoLogger();
|
79 |
+
}
|
80 |
+
|
81 |
+
ob_start();
|
82 |
+
try {
|
83 |
+
$success = WebPConvert::convert($source, $destination, $options, $echoLogger);
|
84 |
+
|
85 |
+
if (!$success) {
|
86 |
+
$msg = 'No converters are operational';
|
87 |
+
}
|
88 |
+
} catch (\WebPConvert\Exceptions\InvalidFileExtensionException $e) {
|
89 |
+
$criticalFail = true;
|
90 |
+
$msg = $e->getMessage();
|
91 |
+
} catch (\WebPConvert\Exceptions\TargetNotFoundException $e) {
|
92 |
+
$criticalFail = true;
|
93 |
+
$msg = $e->getMessage();
|
94 |
+
} catch (\Exception $e) {
|
95 |
+
$msg = $e->getMessage();
|
96 |
+
}
|
97 |
+
$conversionInsights = ob_get_contents();
|
98 |
+
ob_end_clean();
|
99 |
+
|
100 |
+
if ($success) {
|
101 |
+
header('Content-type: image/webp');
|
102 |
+
// Should we add Content-Length header?
|
103 |
+
// header('Content-Length: ' . filesize($file));
|
104 |
+
readfile($destination);
|
105 |
+
return self::$CONVERTED_IMAGE;
|
106 |
+
} else {
|
107 |
+
$action = ($criticalFail ? $criticalFailAction : $failAction);
|
108 |
+
|
109 |
+
switch ($action) {
|
110 |
+
case WebPConvertAndServe::$ORIGINAL:
|
111 |
+
self::serveOriginal($source);
|
112 |
+
break;
|
113 |
+
case WebPConvertAndServe::$HTTP_404:
|
114 |
+
self::serve404();
|
115 |
+
break;
|
116 |
+
case WebPConvertAndServe::$REPORT_AS_IMAGE:
|
117 |
+
self::serveErrorMessageImage($msg);
|
118 |
+
break;
|
119 |
+
case WebPConvertAndServe::$REPORT:
|
120 |
+
echo '<h1>' . $msg . '</h1>';
|
121 |
+
if ($echoLogger) {
|
122 |
+
echo '<p>This is how conversion process went:</p>' . $conversionInsights;
|
123 |
+
}
|
124 |
+
break;
|
125 |
+
}
|
126 |
+
return $action;
|
127 |
+
}
|
128 |
+
}
|
129 |
+
|
130 |
+
public static function convertAndReport($source, $destination, $options)
|
131 |
+
{
|
132 |
+
echo '<html><style>td {vertical-align: top} table {color: #666}</style>';
|
133 |
+
echo '<body><table>';
|
134 |
+
echo '<tr><td><i>source:</i></td><td>' . $source . '</td></tr>';
|
135 |
+
echo '<tr><td><i>destination:</i></td><td>' . $destination . '<td></tr>';
|
136 |
+
|
137 |
+
// Take care of not displaing sensitive converter options.
|
138 |
+
// (psst: the is_callable check is needed in order to work with WebPConvert v1.0)
|
139 |
+
|
140 |
+
if (is_callable('ConverterHelper', 'getClassNameOfConverter')) {
|
141 |
+
|
142 |
+
$printable_options = $options;
|
143 |
+
if (isset($printable_options['converters'])) {
|
144 |
+
foreach ($printable_options['converters'] as &$converter) {
|
145 |
+
if (is_array($converter)) {
|
146 |
+
//echo '::' . $converter['converter'] . '<br>';
|
147 |
+
$className = ConverterHelper::getClassNameOfConverter($converter['converter']);
|
148 |
+
|
149 |
+
// (pstt: the isset check is needed in order to work with WebPConvert v1.0)
|
150 |
+
if (isset($className::$extraOptions)) {
|
151 |
+
foreach ($className::$extraOptions as $extraOption) {
|
152 |
+
if ($extraOption['sensitive']) {
|
153 |
+
if (isset($converter['options'][$extraOption['name']])) {
|
154 |
+
$converter['options'][$extraOption['name']] = '*******';
|
155 |
+
}
|
156 |
+
}
|
157 |
+
}
|
158 |
+
}
|
159 |
+
}
|
160 |
+
}
|
161 |
+
}
|
162 |
+
echo '<tr><td><i>options:</i></td><td>' . print_r($printable_options, true) . '</td></tr>';
|
163 |
+
}
|
164 |
+
echo '</table>';
|
165 |
+
|
166 |
+
// TODO:
|
167 |
+
// We could display warning if unknown options are set
|
168 |
+
// but that requires that WebPConvert also describes its general options
|
169 |
+
|
170 |
+
|
171 |
+
|
172 |
+
echo '<br>';
|
173 |
+
|
174 |
+
try {
|
175 |
+
$echoLogger = null;
|
176 |
+
if (class_exists('WebPConvert\Loggers\EchoLogger')) {
|
177 |
+
$echoLogger = new \WebPConvert\Loggers\EchoLogger();
|
178 |
+
}
|
179 |
+
$success = WebPConvert::convert($source, $destination, $options, $echoLogger);
|
180 |
+
} catch (\Exception $e) {
|
181 |
+
$success = false;
|
182 |
+
|
183 |
+
$msg = $e->getMessage();
|
184 |
+
|
185 |
+
echo '<b>' . $msg . '</b>';
|
186 |
+
exit;
|
187 |
+
}
|
188 |
+
|
189 |
+
if ($success) {
|
190 |
+
//echo 'ok';
|
191 |
+
} else {
|
192 |
+
echo '<b>Conversion failed. None of the tried converters are operational</b>';
|
193 |
+
}
|
194 |
+
echo '</body></html>';
|
195 |
+
}
|
196 |
+
}
|
vendor/webp-convert-and-serve/autoload.php
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
function autoloadWebPConvertAndServe()
|
4 |
+
{
|
5 |
+
$dirsToAutoload = [
|
6 |
+
'../webp-convert',
|
7 |
+
'.',
|
8 |
+
];
|
9 |
+
foreach ($dirsToAutoload as $dir) {
|
10 |
+
$dirAbs = __DIR__ . '/' . $dir;
|
11 |
+
|
12 |
+
// If directory has its own autoload.php, use that (but ignore autoload in current folder)
|
13 |
+
if ((file_exists($dirAbs . '/autoload.php') && ($dir != '.'))) {
|
14 |
+
require_once($dirAbs . '/autoload.php');
|
15 |
+
} else {
|
16 |
+
$files = glob($dirAbs . '/*.php');
|
17 |
+
foreach ($files as $file) {
|
18 |
+
// only require files that begins with uppercase (A-Z)
|
19 |
+
if (preg_match('/\/[A-Z][a-zA-Z]*\.php/', $file)) {
|
20 |
+
require_once($file);
|
21 |
+
}
|
22 |
+
}
|
23 |
+
}
|
24 |
+
}
|
25 |
+
}
|
26 |
+
autoloadWebPConvertAndServe();
|
vendor/webp-convert/Converters/Binaries/cwebp-fbsd
ADDED
Binary file
|
vendor/webp-convert/Converters/Binaries/cwebp-linux
ADDED
Binary file
|
vendor/webp-convert/Converters/Binaries/cwebp-mac12
ADDED
Binary file
|
vendor/webp-convert/Converters/Binaries/cwebp-sol
ADDED
Binary file
|
vendor/webp-convert/Converters/Binaries/cwebp.exe
ADDED
Binary file
|
vendor/webp-convert/Converters/Binaries/test
ADDED
File without changes
|
vendor/webp-convert/Converters/ConverterHelper.php
ADDED
@@ -0,0 +1,260 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace WebPConvert\Converters;
|
4 |
+
|
5 |
+
//use WebPConvert\Converters\Cwebp;
|
6 |
+
|
7 |
+
use WebPConvert\Exceptions\ConverterNotFoundException;
|
8 |
+
use WebPConvert\Exceptions\CreateDestinationFileException;
|
9 |
+
use WebPConvert\Exceptions\CreateDestinationFolderException;
|
10 |
+
use WebPConvert\Exceptions\InvalidFileExtensionException;
|
11 |
+
use WebPConvert\Exceptions\TargetNotFoundException;
|
12 |
+
|
13 |
+
use WebPConvert\Converters\Exceptions\ConverterNotOperationalException;
|
14 |
+
use WebPConvert\Converters\Exceptions\ConverterFailedException;
|
15 |
+
|
16 |
+
class ConverterHelper
|
17 |
+
{
|
18 |
+
public static $allowedExtensions = ['jpg', 'jpeg', 'png'];
|
19 |
+
|
20 |
+
public static $defaultOptions = [
|
21 |
+
'quality' => 'auto',
|
22 |
+
'max-quality' => 85,
|
23 |
+
'default-quality' => 80,
|
24 |
+
'metadata' => 'none',
|
25 |
+
'method' => 6,
|
26 |
+
'low-memory' => false,
|
27 |
+
'lossless' => false,
|
28 |
+
'converters' => ['cwebp', 'gd', 'imagick']
|
29 |
+
];
|
30 |
+
|
31 |
+
public static function mergeOptions($options, $extraOptions)
|
32 |
+
{
|
33 |
+
return $options;
|
34 |
+
}
|
35 |
+
|
36 |
+
public static function getClassNameOfConverter($converterId)
|
37 |
+
{
|
38 |
+
return 'WebPConvert\\Converters\\' . ucfirst($converterId);
|
39 |
+
}
|
40 |
+
|
41 |
+
|
42 |
+
/* Call the "convert" method on a converter, by id.
|
43 |
+
- but also prepares options (merges in the $extraOptions of the converter),
|
44 |
+
prepares destination folder, and runs some standard validations */
|
45 |
+
public static function runConverter($converterId, $source, $destination, $options = [], $prepareDestinationFolder = true, $logger = null)
|
46 |
+
{
|
47 |
+
if ($prepareDestinationFolder) {
|
48 |
+
ConverterHelper::prepareDestinationFolderAndRunCommonValidations($source, $destination);
|
49 |
+
}
|
50 |
+
|
51 |
+
if (!isset($logger)) {
|
52 |
+
$logger = new \WebPConvert\Loggers\VoidLogger();
|
53 |
+
}
|
54 |
+
|
55 |
+
$className = self::getClassNameOfConverter($converterId);
|
56 |
+
if (!is_callable([$className, 'convert'])) {
|
57 |
+
throw new ConverterNotFoundException();
|
58 |
+
}
|
59 |
+
|
60 |
+
// Prepare options.
|
61 |
+
// - Remove 'converters'
|
62 |
+
$defaultOptions = self::$defaultOptions;
|
63 |
+
unset($defaultOptions['converters']);
|
64 |
+
|
65 |
+
// - Merge defaults of the converters extra options into the standard default options.
|
66 |
+
$defaultOptions = array_merge($defaultOptions, array_column($className::$extraOptions, 'default', 'name'));
|
67 |
+
|
68 |
+
// - Merge $defaultOptions into provided options
|
69 |
+
$options = array_merge($defaultOptions, $options);
|
70 |
+
|
71 |
+
// Individual converters do not accept quality = auto. They need a number.
|
72 |
+
// Change $options['quality'] to number, based on quality of source and several settings
|
73 |
+
|
74 |
+
self::processQualityOption($source, $options, $logger);
|
75 |
+
|
76 |
+
call_user_func(
|
77 |
+
[$className, 'doConvert'],
|
78 |
+
$source,
|
79 |
+
$destination,
|
80 |
+
$options,
|
81 |
+
$logger
|
82 |
+
);
|
83 |
+
|
84 |
+
if (!file_exists($destination)) {
|
85 |
+
throw new ConverterFailedException('Destination file is not there');
|
86 |
+
}
|
87 |
+
}
|
88 |
+
|
89 |
+
/* Try to detect quality of jpeg.
|
90 |
+
If not possible, nothing is returned (null). Otherwise quality is returned (int)
|
91 |
+
*/
|
92 |
+
public static function detectQualityOfJpg($filename)
|
93 |
+
{
|
94 |
+
// Try Imagick extension
|
95 |
+
if (extension_loaded('imagick') && class_exists('Imagick')) {
|
96 |
+
$img = new Imagick($filename);
|
97 |
+
|
98 |
+
// The required function is available as from PECL imagick v2.2.2
|
99 |
+
if (method_exists($img, 'getImageCompressionQuality')) {
|
100 |
+
return $img->getImageCompressionQuality();
|
101 |
+
}
|
102 |
+
}
|
103 |
+
|
104 |
+
if (function_exists('shell_exec')) {
|
105 |
+
|
106 |
+
// Try Imagick
|
107 |
+
$quality = shell_exec("identify -format '%Q' " . $filename);
|
108 |
+
if ($quality) {
|
109 |
+
return intval($quality);
|
110 |
+
}
|
111 |
+
|
112 |
+
// Try GraphicsMagick
|
113 |
+
$quality = shell_exec("gm identify -format '%Q' " . $filename);
|
114 |
+
if ($quality) {
|
115 |
+
return intval($quality);
|
116 |
+
}
|
117 |
+
}
|
118 |
+
}
|
119 |
+
|
120 |
+
public static function processQualityOption($source, &$options, $logger)
|
121 |
+
{
|
122 |
+
if (isset($options['_calculated_quality'])) {
|
123 |
+
return;
|
124 |
+
}
|
125 |
+
if ($options['quality'] == 'auto') {
|
126 |
+
$q = self::detectQualityOfJpg($source);
|
127 |
+
//$logger->log('Quality set to auto... Quality of source: ');
|
128 |
+
if (!$q) {
|
129 |
+
$q = $options['default-quality'];
|
130 |
+
$logger->logLn('Quality of source could not be established (Imagick or GraphicsMagick is required) - Using default instead (' . $options['default-quality'] . ').');
|
131 |
+
|
132 |
+
// this allows the wpc converter to know
|
133 |
+
$options['_quality_could_not_be_detected'] = true;
|
134 |
+
} else {
|
135 |
+
if ($q > $options['max-quality']) {
|
136 |
+
$logger->log('Quality of source is ' . $q . '. This is higher than max-quality, so using that instead (' . $options['max-quality'] . ')');
|
137 |
+
} else {
|
138 |
+
$logger->log('Quality set to same as source: ' . $q);
|
139 |
+
}
|
140 |
+
}
|
141 |
+
$logger->ln();
|
142 |
+
$q = min($q, $options['max-quality']);
|
143 |
+
|
144 |
+
$options['_calculated_quality'] = $q;
|
145 |
+
//$logger->logLn('Using quality: ' . $options['quality']);
|
146 |
+
} else {
|
147 |
+
$logger->logLn('Quality: ' . $options['quality'] . '. Consider setting quality to "auto" instead. It is generally a better idea');
|
148 |
+
$options['_calculated_quality'] = $options['quality'];
|
149 |
+
}
|
150 |
+
$logger->ln();
|
151 |
+
}
|
152 |
+
|
153 |
+
|
154 |
+
public static function getExtension($filePath)
|
155 |
+
{
|
156 |
+
$fileExtension = pathinfo($filePath, PATHINFO_EXTENSION);
|
157 |
+
return strtolower($fileExtension);
|
158 |
+
}
|
159 |
+
|
160 |
+
// Throws an exception if the provided file doesn't exist
|
161 |
+
public static function isValidTarget($filePath)
|
162 |
+
{
|
163 |
+
if (!file_exists($filePath)) {
|
164 |
+
throw new TargetNotFoundException('File or directory not found: ' . $filePath);
|
165 |
+
}
|
166 |
+
|
167 |
+
return true;
|
168 |
+
}
|
169 |
+
|
170 |
+
// Throws an exception if the provided file's extension is invalid
|
171 |
+
public static function isAllowedExtension($filePath)
|
172 |
+
{
|
173 |
+
$fileExtension = pathinfo($filePath, PATHINFO_EXTENSION);
|
174 |
+
if (!in_array(strtolower($fileExtension), self::$allowedExtensions)) {
|
175 |
+
throw new InvalidFileExtensionException('Unsupported file extension: ' . $fileExtension);
|
176 |
+
}
|
177 |
+
|
178 |
+
return true;
|
179 |
+
}
|
180 |
+
|
181 |
+
// Creates folder in provided path & sets correct permissions
|
182 |
+
public static function createWritableFolder($filePath)
|
183 |
+
{
|
184 |
+
$folder = pathinfo($filePath, PATHINFO_DIRNAME);
|
185 |
+
if (!file_exists($folder)) {
|
186 |
+
// TODO: what if this is outside open basedir?
|
187 |
+
// see http://php.net/manual/en/ini.core.php#ini.open-basedir
|
188 |
+
|
189 |
+
// First, we have to figure out which permissions to set.
|
190 |
+
// We want same permissions as parent folder
|
191 |
+
// But which parent? - the parent to the first missing folder
|
192 |
+
|
193 |
+
$parentFolders = explode('/', $folder);
|
194 |
+
$poppedFolders = [];
|
195 |
+
|
196 |
+
while (!(file_exists(implode('/', $parentFolders))) && count($parentFolders) > 0) {
|
197 |
+
array_unshift($poppedFolders, array_pop($parentFolders));
|
198 |
+
}
|
199 |
+
|
200 |
+
// Retrieving permissions of closest existing folder
|
201 |
+
$closestExistingFolder = implode('/', $parentFolders);
|
202 |
+
$permissions = fileperms($closestExistingFolder) & 000777;
|
203 |
+
|
204 |
+
// Trying to create the given folder
|
205 |
+
// Notice: mkdir emits a warning on failure. It would be nice to suppress that, if possible
|
206 |
+
if (!mkdir($folder, $permissions, true)) {
|
207 |
+
throw new CreateDestinationFolderException('Failed creating folder: ' . $folder);
|
208 |
+
}
|
209 |
+
|
210 |
+
|
211 |
+
// `mkdir` doesn't respect permissions, so we have to `chmod` each created subfolder
|
212 |
+
foreach ($poppedFolders as $subfolder) {
|
213 |
+
$closestExistingFolder .= '/' . $subfolder;
|
214 |
+
// Setting directory permissions
|
215 |
+
chmod($folder, $permissions);
|
216 |
+
}
|
217 |
+
}
|
218 |
+
|
219 |
+
// Checks if there's a file in $filePath & if writing permissions are correct
|
220 |
+
if (file_exists($filePath) && !is_writable($filePath)) {
|
221 |
+
throw new CreateDestinationFileException('Cannot overwrite ' . basename($filePath) . ' - check file permissions.');
|
222 |
+
}
|
223 |
+
|
224 |
+
// There's either a rewritable file in $filePath or none at all.
|
225 |
+
// If there is, simply attempt to delete it
|
226 |
+
if (file_exists($filePath) && !unlink($filePath)) {
|
227 |
+
throw new CreateDestinationFileException('Existing file cannot be removed: ' . basename($filePath));
|
228 |
+
}
|
229 |
+
|
230 |
+
return true;
|
231 |
+
}
|
232 |
+
|
233 |
+
public static function prepareDestinationFolderAndRunCommonValidations($source, $destination)
|
234 |
+
{
|
235 |
+
self::isValidTarget($source);
|
236 |
+
self::isAllowedExtension($source);
|
237 |
+
self::createWritableFolder($destination);
|
238 |
+
}
|
239 |
+
|
240 |
+
public static function initCurlForConverter()
|
241 |
+
{
|
242 |
+
if (!extension_loaded('curl')) {
|
243 |
+
throw new ConverterNotOperationalException('Required cURL extension is not available.');
|
244 |
+
}
|
245 |
+
|
246 |
+
if (!function_exists('curl_init')) {
|
247 |
+
throw new ConverterNotOperationalException('Required url_init() function is not available.');
|
248 |
+
}
|
249 |
+
|
250 |
+
if (!function_exists('curl_file_create')) {
|
251 |
+
throw new ConverterNotOperationalException('Required curl_file_create() function is not available (requires PHP > 5.5).');
|
252 |
+
}
|
253 |
+
|
254 |
+
$ch = curl_init();
|
255 |
+
if (!$ch) {
|
256 |
+
throw new ConverterNotOperationalException('Could not initialise cURL.');
|
257 |
+
}
|
258 |
+
return $ch;
|
259 |
+
}
|
260 |
+
}
|
vendor/webp-convert/Converters/Cwebp.php
ADDED
@@ -0,0 +1,246 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace WebPConvert\Converters;
|
4 |
+
|
5 |
+
use WebPConvert\Converters\Exceptions\ConverterNotOperationalException;
|
6 |
+
use WebPConvert\Converters\Exceptions\ConverterFailedException;
|
7 |
+
|
8 |
+
class Cwebp
|
9 |
+
{
|
10 |
+
public static $extraOptions = [
|
11 |
+
[
|
12 |
+
'name' => 'use-nice',
|
13 |
+
'type' => 'boolean',
|
14 |
+
'sensitive' => false,
|
15 |
+
'default' => false,
|
16 |
+
'required' => false
|
17 |
+
],
|
18 |
+
];
|
19 |
+
|
20 |
+
public static function convert($source, $destination, $options = [])
|
21 |
+
{
|
22 |
+
ConverterHelper::runConverter('cwebp', $source, $destination, $options, true);
|
23 |
+
}
|
24 |
+
|
25 |
+
// System paths to look for cwebp binary
|
26 |
+
private static $cwebpDefaultPaths = [
|
27 |
+
'/usr/bin/cwebp',
|
28 |
+
'/usr/local/bin/cwebp',
|
29 |
+
'/usr/gnu/bin/cwebp',
|
30 |
+
'/usr/syno/bin/cwebp'
|
31 |
+
];
|
32 |
+
|
33 |
+
// OS-specific binaries included in this library, along with hashes
|
34 |
+
private static $suppliedBinariesInfo = [
|
35 |
+
'WinNT' => [ 'cwebp.exe', '49e9cb98db30bfa27936933e6fd94d407e0386802cb192800d9fd824f6476873'],
|
36 |
+
'Darwin' => [ 'cwebp-mac12', 'a06a3ee436e375c89dbc1b0b2e8bd7729a55139ae072ed3f7bd2e07de0ebb379'],
|
37 |
+
'SunOS' => [ 'cwebp-sol', '1febaffbb18e52dc2c524cda9eefd00c6db95bc388732868999c0f48deb73b4f'],
|
38 |
+
'FreeBSD' => [ 'cwebp-fbsd', 'e5cbea11c97fadffe221fdf57c093c19af2737e4bbd2cb3cd5e908de64286573'],
|
39 |
+
'Linux' => [ 'cwebp-linux', '916623e5e9183237c851374d969aebdb96e0edc0692ab7937b95ea67dc3b2568']
|
40 |
+
];
|
41 |
+
|
42 |
+
private static function escapeFilename($string)
|
43 |
+
{
|
44 |
+
// Escaping whitespaces & quotes
|
45 |
+
$string = preg_replace('/\s/', '\\ ', $string);
|
46 |
+
$string = filter_var($string, FILTER_SANITIZE_MAGIC_QUOTES);
|
47 |
+
|
48 |
+
// Stripping control characters
|
49 |
+
// see https://stackoverflow.com/questions/12769462/filter-flag-strip-low-vs-filter-flag-strip-high
|
50 |
+
$string = filter_var($string, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW);
|
51 |
+
|
52 |
+
return $string;
|
53 |
+
}
|
54 |
+
|
55 |
+
// Checks if 'Nice' is available
|
56 |
+
private static function hasNiceSupport()
|
57 |
+
{
|
58 |
+
exec("nice 2>&1", $niceOutput);
|
59 |
+
|
60 |
+
if (is_array($niceOutput) && isset($niceOutput[0])) {
|
61 |
+
if (preg_match('/usage/', $niceOutput[0]) || (preg_match('/^\d+$/', $niceOutput[0]))) {
|
62 |
+
/*
|
63 |
+
* Nice is available - default niceness (+10)
|
64 |
+
* https://www.lifewire.com/uses-of-commands-nice-renice-2201087
|
65 |
+
* https://www.computerhope.com/unix/unice.htm
|
66 |
+
*/
|
67 |
+
|
68 |
+
return true;
|
69 |
+
}
|
70 |
+
|
71 |
+
return false;
|
72 |
+
}
|
73 |
+
}
|
74 |
+
|
75 |
+
//
|
76 |
+
private static function executeBinary($binary, $commandOptions, $useNice, $logger)
|
77 |
+
{
|
78 |
+
$command = ($useNice ? 'nice ' : '') . $binary . ' ' . $commandOptions;
|
79 |
+
|
80 |
+
$logger->logLn('Trying to execute binary:' . $binary);
|
81 |
+
//$logger->logLn();
|
82 |
+
|
83 |
+
exec($command, $output, $returnCode);
|
84 |
+
|
85 |
+
switch ($returnCode) {
|
86 |
+
case 0:
|
87 |
+
$logger->logLn('Success!');
|
88 |
+
break;
|
89 |
+
case 126:
|
90 |
+
$logger->logLn('Permission denied. The user that the command was run with (' . shell_exec('whoami') . ') does not have permission to execute that binary.');
|
91 |
+
break;
|
92 |
+
case 127:
|
93 |
+
$logger->logLn('No binary found at that location');
|
94 |
+
break;
|
95 |
+
default:
|
96 |
+
$logger->logLn('Failed. Return code:' . $returnCode . '. See http://tldp.org/LDP/abs/html/exitcodes.html for failcodes');
|
97 |
+
}
|
98 |
+
return $returnCode;
|
99 |
+
}
|
100 |
+
|
101 |
+
// Although this method is public, do not call directly.
|
102 |
+
public static function doConvert($source, $destination, $options = [], $logger)
|
103 |
+
{
|
104 |
+
$errorMsg = '';
|
105 |
+
// Force lossless option to true for PNG images
|
106 |
+
if (ConverterHelper::getExtension($source) == 'png') {
|
107 |
+
$options['lossless'] = true;
|
108 |
+
}
|
109 |
+
|
110 |
+
if (!function_exists('exec')) {
|
111 |
+
throw new ConverterNotOperationalException('exec() is not enabled.');
|
112 |
+
}
|
113 |
+
|
114 |
+
/*
|
115 |
+
* Prepare cwebp options
|
116 |
+
*/
|
117 |
+
|
118 |
+
// Metadata (all, exif, icc, xmp or none (default))
|
119 |
+
// Comma-separated list of existing metadata to copy from input to output
|
120 |
+
$metadata = '-metadata ' . $options['metadata'];
|
121 |
+
|
122 |
+
// Image quality
|
123 |
+
$quality = '-q ' . $options['_calculated_quality'];
|
124 |
+
|
125 |
+
// Losless PNG conversion
|
126 |
+
$lossless = ($options['lossless'] ? '-lossless' : '');
|
127 |
+
|
128 |
+
// Built-in method option
|
129 |
+
$method = ' -m ' . strval($options['method']);
|
130 |
+
|
131 |
+
|
132 |
+
// TODO:
|
133 |
+
// Why not use -af ? (https://developers.google.com/speed/webp/docs/cwebp)
|
134 |
+
// Would it be possible get a quality similar to source?
|
135 |
+
// It seems so: "identify -format '%Q' yourimage.jpg" (https://stackoverflow.com/questions/2024947/is-it-possible-to-tell-the-quality-level-of-a-jpeg)
|
136 |
+
// -- With -jpeg_like option, or perhaps the -size option
|
137 |
+
|
138 |
+
// Built-in low memory option
|
139 |
+
$lowMemory = '';
|
140 |
+
if ($options['low-memory']) {
|
141 |
+
$lowMemory = '-low_memory';
|
142 |
+
}
|
143 |
+
|
144 |
+
$commandOptionsArray = [
|
145 |
+
$metadata = $metadata,
|
146 |
+
$quality = $quality,
|
147 |
+
$lossless = $lossless,
|
148 |
+
$method = $method,
|
149 |
+
$lowMemory = $lowMemory,
|
150 |
+
$input = self::escapeFilename($source),
|
151 |
+
$output = '-o ' . self::escapeFilename($destination),
|
152 |
+
$stderrRedirect = '2>&1'
|
153 |
+
];
|
154 |
+
|
155 |
+
$useNice = (($options['use-nice']) && self::hasNiceSupport()) ? true : false;
|
156 |
+
|
157 |
+
$commandOptions = implode(' ', $commandOptionsArray);
|
158 |
+
|
159 |
+
|
160 |
+
// Init with common system paths
|
161 |
+
$cwebpPathsToTest = self::$cwebpDefaultPaths;
|
162 |
+
|
163 |
+
// Remove paths that doesn't exist
|
164 |
+
$cwebpPathsToTest = array_filter($cwebpPathsToTest, function ($binary) {
|
165 |
+
//return file_exists($binary);
|
166 |
+
return @is_readable($binary);
|
167 |
+
});
|
168 |
+
|
169 |
+
// Try all common paths that exitst
|
170 |
+
$success = false;
|
171 |
+
foreach ($cwebpPathsToTest as $index => $binary) {
|
172 |
+
$success = (self::executeBinary($binary, $commandOptions, $useNice, $logger) == 0);
|
173 |
+
if ($success) {
|
174 |
+
break;
|
175 |
+
}
|
176 |
+
}
|
177 |
+
if (!$success) {
|
178 |
+
//$logger->logLn('');
|
179 |
+
if (count($cwebpPathsToTest) > 0) {
|
180 |
+
$errorMsg .= 'Found cwebp binaries at these locations: "' . implode('", "', $cwebpPathsToTest) . '". However, executing these failed. ';
|
181 |
+
} else {
|
182 |
+
$errorMsg .= 'Found no cwebp binaries in any common locations. ';
|
183 |
+
}
|
184 |
+
}
|
185 |
+
|
186 |
+
if (!$success) {
|
187 |
+
|
188 |
+
// Try supplied binary (if available for OS, and hash is correct)
|
189 |
+
if (isset(self::$suppliedBinariesInfo[PHP_OS])) {
|
190 |
+
$info = self::$suppliedBinariesInfo[PHP_OS];
|
191 |
+
|
192 |
+
$file = $info[0];
|
193 |
+
$hash = $info[1];
|
194 |
+
|
195 |
+
$binaryFile = __DIR__ . '/Binaries/' . $file;
|
196 |
+
|
197 |
+
// The file should exist, but may have been removed manually.
|
198 |
+
if (file_exists($binaryFile)) {
|
199 |
+
// File exists, now generate its hash
|
200 |
+
$binaryHash = hash_file('sha256', $binaryFile);
|
201 |
+
|
202 |
+
// Throw an exception if binary file checksum & deposited checksum do not match
|
203 |
+
if ($binaryHash != $hash) {
|
204 |
+
//throw new ConverterNotOperationalException('Binary checksum is invalid.');
|
205 |
+
$errorMsg .= 'Binary checksum of supplied binary is invalid! Did you transfer with FTP, but not in binary mode? File:' . $binaryFile . '. Expected checksum: ' . $hash . ' Actual checksum:' . $binaryHash . '. ';
|
206 |
+
} else {
|
207 |
+
$returnCode = self::executeBinary($binaryFile, $commandOptions, $useNice, $logger);
|
208 |
+
if ($returnCode == 0) {
|
209 |
+
$success = true;
|
210 |
+
} else {
|
211 |
+
$errorMsg .= 'Tried executing supplied binary (' . $binaryFile . '), but that failed too: ';
|
212 |
+
switch ($returnCode) {
|
213 |
+
case 126:
|
214 |
+
$errorMsg .= 'Permission denied (user "' . trim(shell_exec('whoami')) . '" does not have permission to execute the binary)';
|
215 |
+
break;
|
216 |
+
default:
|
217 |
+
$errorMsg .= 'Fail code: ' . $returnCode;
|
218 |
+
}
|
219 |
+
}
|
220 |
+
}
|
221 |
+
} else {
|
222 |
+
$errorMsg .= 'Supplied binary not found:' . $binaryFile;
|
223 |
+
}
|
224 |
+
} else {
|
225 |
+
$errorMsg .= 'No supplied binaries found for OS:' . PHP_OS;
|
226 |
+
}
|
227 |
+
}
|
228 |
+
|
229 |
+
|
230 |
+
|
231 |
+
// cwebp sets file permissions to 664 but instead ..
|
232 |
+
// .. $destination's parent folder's permissions should be used (except executable bits)
|
233 |
+
if ($success) {
|
234 |
+
$destinationParent = dirname($destination);
|
235 |
+
$fileStatistics = stat($destinationParent);
|
236 |
+
|
237 |
+
// Apply same permissions as parent folder but strip off the executable bits
|
238 |
+
$permissions = $fileStatistics['mode'] & 0000666;
|
239 |
+
chmod($destination, $permissions);
|
240 |
+
}
|
241 |
+
|
242 |
+
if (!$success) {
|
243 |
+
throw new ConverterNotOperationalException($errorMsg);
|
244 |
+
}
|
245 |
+
}
|
246 |
+
}
|
vendor/webp-convert/Converters/Ewww.php
ADDED
@@ -0,0 +1,197 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace WebPConvert\Converters;
|
4 |
+
|
5 |
+
use WebPConvert\Converters\Exceptions\ConverterNotOperationalException;
|
6 |
+
use WebPConvert\Converters\Exceptions\ConverterFailedException;
|
7 |
+
|
8 |
+
class Ewww
|
9 |
+
{
|
10 |
+
public static $extraOptions = [
|
11 |
+
[
|
12 |
+
'name' => 'key',
|
13 |
+
'type' => 'string',
|
14 |
+
'sensitive' => true,
|
15 |
+
'default' => '',
|
16 |
+
'required' => true
|
17 |
+
],
|
18 |
+
];
|
19 |
+
|
20 |
+
public static function convert($source, $destination, $options = [])
|
21 |
+
{
|
22 |
+
ConverterHelper::runConverter('ewww', $source, $destination, $options, true);
|
23 |
+
}
|
24 |
+
|
25 |
+
// Although this method is public, do not call directly.
|
26 |
+
public static function doConvert($source, $destination, $options = [], $logger)
|
27 |
+
{
|
28 |
+
if ($options['key'] == '') {
|
29 |
+
throw new ConverterNotOperationalException('Missing API key.');
|
30 |
+
}
|
31 |
+
if (strlen($options['key']) < 20) {
|
32 |
+
throw new ConverterNotOperationalException('Key is invalid. Keys are supposed to be 32 characters long - your key is much shorter');
|
33 |
+
}
|
34 |
+
|
35 |
+
$keyStatus = self::getKeyStatus($options['key']);
|
36 |
+
switch ($keyStatus) {
|
37 |
+
case 'great':
|
38 |
+
break;
|
39 |
+
case 'exceeded':
|
40 |
+
throw new ConverterNotOperationalException('quota has exceeded');
|
41 |
+
break;
|
42 |
+
case 'invalid':
|
43 |
+
throw new ConverterNotOperationalException('key is invalid');
|
44 |
+
break;
|
45 |
+
}
|
46 |
+
|
47 |
+
$ch = ConverterHelper::initCurlForConverter();
|
48 |
+
|
49 |
+
$curlOptions = [
|
50 |
+
'api_key' => $options['key'],
|
51 |
+
'webp' => '1',
|
52 |
+
'file' => curl_file_create($source),
|
53 |
+
'domain' => $_SERVER['HTTP_HOST'],
|
54 |
+
'quality' => $options['_calculated_quality'],
|
55 |
+
'metadata' => ($options['metadata'] == 'none' ? '0' : '1')
|
56 |
+
];
|
57 |
+
|
58 |
+
curl_setopt_array($ch, [
|
59 |
+
CURLOPT_URL => "https://optimize.exactlywww.com/v2/",
|
60 |
+
CURLOPT_HTTPHEADER => [
|
61 |
+
'User-Agent: WebPConvert',
|
62 |
+
'Accept: image/*'
|
63 |
+
],
|
64 |
+
CURLOPT_POSTFIELDS => $curlOptions,
|
65 |
+
CURLOPT_BINARYTRANSFER => true,
|
66 |
+
CURLOPT_RETURNTRANSFER => true,
|
67 |
+
CURLOPT_HEADER => false,
|
68 |
+
CURLOPT_SSL_VERIFYPEER => false
|
69 |
+
]);
|
70 |
+
|
71 |
+
$response = curl_exec($ch);
|
72 |
+
|
73 |
+
if (curl_errno($ch)) {
|
74 |
+
throw new ConverterNotOperationalException(curl_error($ch));
|
75 |
+
}
|
76 |
+
|
77 |
+
// The API does not always return images.
|
78 |
+
// For example, it may return a message such as '{"error":"invalid","t":"exceeded"}
|
79 |
+
// Messages has a http content type of ie 'text/html; charset=UTF-8
|
80 |
+
// Images has application/octet-stream.
|
81 |
+
// So verify that we got an image back.
|
82 |
+
if (curl_getinfo($ch, CURLINFO_CONTENT_TYPE) != 'application/octet-stream') {
|
83 |
+
|
84 |
+
//echo curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
|
85 |
+
curl_close($ch);
|
86 |
+
|
87 |
+
/* May return this: {"error":"invalid","t":"exceeded"} */
|
88 |
+
$responseObj = json_decode($response);
|
89 |
+
if (isset($responseObj->error)) {
|
90 |
+
//echo 'error:' . $responseObj->error . '<br>';
|
91 |
+
//echo $response;
|
92 |
+
//self::blacklistKey($key);
|
93 |
+
//throw new ConverterNotOperationalException('The key is invalid. Blacklisted it!');
|
94 |
+
throw new ConverterNotOperationalException('The key is invalid');
|
95 |
+
}
|
96 |
+
|
97 |
+
throw new ConverterNotOperationalException('ewww api did not return an image. It could be that the key is invalid. Response: ' . $response);
|
98 |
+
}
|
99 |
+
|
100 |
+
// Not sure this can happen. So just in case
|
101 |
+
if ($response == '') {
|
102 |
+
throw new ConverterNotOperationalException('ewww api did not return anything');
|
103 |
+
}
|
104 |
+
|
105 |
+
$success = file_put_contents($destination, $response);
|
106 |
+
|
107 |
+
if (!$success) {
|
108 |
+
throw new ConverterFailedException('Error saving file');
|
109 |
+
}
|
110 |
+
}
|
111 |
+
|
112 |
+
/*
|
113 |
+
public static function blacklistKey($key)
|
114 |
+
{
|
115 |
+
}
|
116 |
+
|
117 |
+
public static function isKeyBlacklisted($key)
|
118 |
+
{
|
119 |
+
}*/
|
120 |
+
|
121 |
+
/**
|
122 |
+
* Return "great", "exceeded" or "invalid"
|
123 |
+
*/
|
124 |
+
public static function getKeyStatus($key)
|
125 |
+
{
|
126 |
+
$ch = ConverterHelper::initCurlForConverter();
|
127 |
+
|
128 |
+
curl_setopt($ch, CURLOPT_URL, "https://optimize.exactlywww.com/verify/");
|
129 |
+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
130 |
+
curl_setopt($ch, CURLOPT_POSTFIELDS, [
|
131 |
+
'api_key' => $key
|
132 |
+
]);
|
133 |
+
|
134 |
+
// The 403 forbidden is avoided with this line.
|
135 |
+
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)');
|
136 |
+
|
137 |
+
$response = curl_exec($ch);
|
138 |
+
// echo $response;
|
139 |
+
if (curl_errno($ch)) {
|
140 |
+
throw new \Exception(curl_error($ch));
|
141 |
+
}
|
142 |
+
curl_close($ch);
|
143 |
+
|
144 |
+
// Possible responses:
|
145 |
+
// “great” = verification successful
|
146 |
+
// “exceeded” = indicates a valid key with no remaining image credits.
|
147 |
+
// an empty response indicates that the key is not valid
|
148 |
+
|
149 |
+
if ($response == '') {
|
150 |
+
return 'invalid';
|
151 |
+
}
|
152 |
+
$responseObj = json_decode($response);
|
153 |
+
if (isset($responseObj->error)) {
|
154 |
+
if ($responseObj->error == 'invalid') {
|
155 |
+
return 'invalid';
|
156 |
+
} else {
|
157 |
+
throw new \Exception('Ewww returned unexpected error: ' . $response);
|
158 |
+
}
|
159 |
+
}
|
160 |
+
if (!isset($responseObj->status)) {
|
161 |
+
throw new \Exception('Ewww returned unexpected response to verify request: ' . $response);
|
162 |
+
}
|
163 |
+
switch ($responseObj->status) {
|
164 |
+
case 'great':
|
165 |
+
case 'exceeded':
|
166 |
+
return $responseObj->status;
|
167 |
+
}
|
168 |
+
throw new \Exception('Ewww returned unexpected status to verify request: "' . $responseObj->status . '"');
|
169 |
+
}
|
170 |
+
|
171 |
+
public static function isWorkingKey($key)
|
172 |
+
{
|
173 |
+
return (self::getKeyStatus($key) == 'great');
|
174 |
+
}
|
175 |
+
|
176 |
+
public static function isValidKey($key)
|
177 |
+
{
|
178 |
+
return (self::getKeyStatus($key) != 'invalid');
|
179 |
+
}
|
180 |
+
|
181 |
+
public static function getQuota($key)
|
182 |
+
{
|
183 |
+
$ch = ConverterHelper::initCurlForConverter();
|
184 |
+
|
185 |
+
curl_setopt($ch, CURLOPT_URL, "https://optimize.exactlywww.com/quota/");
|
186 |
+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
187 |
+
curl_setopt($ch, CURLOPT_POSTFIELDS, [
|
188 |
+
'api_key' => $key
|
189 |
+
]);
|
190 |
+
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)');
|
191 |
+
|
192 |
+
$response = curl_exec($ch);
|
193 |
+
return $response; // ie -830 23. Seems to return empty for invalid keys
|
194 |
+
// or empty
|
195 |
+
//echo $response;
|
196 |
+
}
|
197 |
+
}
|
vendor/webp-convert/Converters/Exceptions/ConversionDeclinedException.php
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace WebPConvert\Converters\Exceptions;
|
4 |
+
|
5 |
+
use WebPConvert\Exceptions\WebPConvertBaseException;
|
6 |
+
|
7 |
+
class ConversionDeclinedException extends WebPConvertBaseException
|
8 |
+
{
|
9 |
+
public $description = 'The converter declined converting';
|
10 |
+
}
|
vendor/webp-convert/Converters/Exceptions/ConverterFailedException.php
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace WebPConvert\Converters\Exceptions;
|
4 |
+
|
5 |
+
use WebPConvert\Exceptions\WebPConvertBaseException;
|
6 |
+
|
7 |
+
class ConverterFailedException extends WebPConvertBaseException
|
8 |
+
{
|
9 |
+
public $description = 'The converter failed converting, although requirements seemed to be met';
|
10 |
+
}
|
vendor/webp-convert/Converters/Exceptions/ConverterNotOperationalException.php
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace WebPConvert\Converters\Exceptions;
|
4 |
+
|
5 |
+
use WebPConvert\Exceptions\WebPConvertBaseException;
|
6 |
+
|
7 |
+
class ConverterNotOperationalException extends WebPConvertBaseException
|
8 |
+
{
|
9 |
+
public $description = 'The converter is not operational';
|
10 |
+
}
|
vendor/webp-convert/Converters/Gd.php
ADDED
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace WebPConvert\Converters;
|
4 |
+
|
5 |
+
use WebPConvert\Converters\Exceptions\ConverterNotOperationalException;
|
6 |
+
use WebPConvert\Converters\Exceptions\ConverterFailedException;
|
7 |
+
use WebPConvert\Converters\Exceptions\ConversionDeclinedException;
|
8 |
+
|
9 |
+
use WebPConvert\Converters\ConverterHelper;
|
10 |
+
|
11 |
+
class Gd
|
12 |
+
{
|
13 |
+
public static $extraOptions = [
|
14 |
+
[
|
15 |
+
'name' => 'skip-pngs',
|
16 |
+
'type' => 'boolean',
|
17 |
+
'sensitive' => false,
|
18 |
+
'default' => true,
|
19 |
+
'required' => false
|
20 |
+
],
|
21 |
+
];
|
22 |
+
|
23 |
+
public static function convert($source, $destination, $options = [])
|
24 |
+
{
|
25 |
+
ConverterHelper::runConverter('gd', $source, $destination, $options, true);
|
26 |
+
}
|
27 |
+
|
28 |
+
// Although this method is public, do not call directly.
|
29 |
+
public static function doConvert($source, $destination, $options = [], $logger)
|
30 |
+
{
|
31 |
+
if (!extension_loaded('gd')) {
|
32 |
+
throw new ConverterNotOperationalException('Required GD extension is not available.');
|
33 |
+
}
|
34 |
+
|
35 |
+
if (!function_exists('imagewebp')) {
|
36 |
+
throw new ConverterNotOperationalException('Required imagewebp() function is not available.');
|
37 |
+
}
|
38 |
+
|
39 |
+
switch (ConverterHelper::getExtension($source)) {
|
40 |
+
case 'png':
|
41 |
+
if (!$options['skip-pngs']) {
|
42 |
+
if (!function_exists('imagecreatefrompng')) {
|
43 |
+
throw new ConverterNotOperationalException('Required imagecreatefrompng() function is not available.');
|
44 |
+
}
|
45 |
+
$image = imagecreatefrompng($source);
|
46 |
+
if (!$image) {
|
47 |
+
throw new ConverterFailedException('imagecreatefrompng("' . $source . '") failed');
|
48 |
+
}
|
49 |
+
} else {
|
50 |
+
throw new ConversionDeclinedException('PNG file skipped. GD is configured not to convert PNGs');
|
51 |
+
}
|
52 |
+
break;
|
53 |
+
default:
|
54 |
+
if (!function_exists('imagecreatefromjpeg')) {
|
55 |
+
throw new ConverterNotOperationalException('Required imagecreatefromjpeg() function is not available.');
|
56 |
+
}
|
57 |
+
$image = imagecreatefromjpeg($source);
|
58 |
+
if (!$image) {
|
59 |
+
throw new ConverterFailedException('imagecreatefromjpeg("' . $source . '") failed');
|
60 |
+
}
|
61 |
+
}
|
62 |
+
|
63 |
+
// Checks if either imagecreatefromjpeg() or imagecreatefrompng() returned false
|
64 |
+
|
65 |
+
$success = imagewebp($image, $destination, $options['_calculated_quality']);
|
66 |
+
|
67 |
+
if (!$success) {
|
68 |
+
throw new ConverterFailedException('Call to imagewebp() failed. Probably failed writing file');
|
69 |
+
}
|
70 |
+
|
71 |
+
/*
|
72 |
+
* This hack solves an `imagewebp` bug
|
73 |
+
* See https://stackoverflow.com/questions/30078090/imagewebp-php-creates-corrupted-webp-files
|
74 |
+
*
|
75 |
+
*/
|
76 |
+
|
77 |
+
if (filesize($destination) % 2 == 1) {
|
78 |
+
file_put_contents($destination, "\0", FILE_APPEND);
|
79 |
+
}
|
80 |
+
|
81 |
+
imagedestroy($image);
|
82 |
+
}
|
83 |
+
}
|
vendor/webp-convert/Converters/Imagick.php
ADDED
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace WebPConvert\Converters;
|
4 |
+
|
5 |
+
use WebPConvert\Converters\Exceptions\ConverterNotOperationalException;
|
6 |
+
use WebPConvert\Converters\Exceptions\ConverterFailedException;
|
7 |
+
|
8 |
+
//use WebPConvert\Exceptions\TargetNotFoundException;
|
9 |
+
|
10 |
+
class Imagick
|
11 |
+
{
|
12 |
+
public static $extraOptions = [];
|
13 |
+
|
14 |
+
public static function convert($source, $destination, $options = [])
|
15 |
+
{
|
16 |
+
ConverterHelper::runConverter('imagick', $source, $destination, $options, true);
|
17 |
+
}
|
18 |
+
|
19 |
+
// Although this method is public, do not call directly.
|
20 |
+
public static function doConvert($source, $destination, $options = [], $logger)
|
21 |
+
{
|
22 |
+
if (!extension_loaded('imagick')) {
|
23 |
+
throw new ConverterNotOperationalException('Required iMagick extension is not available.');
|
24 |
+
}
|
25 |
+
|
26 |
+
if (!class_exists('Imagick')) {
|
27 |
+
throw new ConverterNotOperationalException('iMagick is installed, but not correctly. The class Imagick is not available');
|
28 |
+
}
|
29 |
+
|
30 |
+
$im = new \Imagick($source);
|
31 |
+
|
32 |
+
// Throws an exception if iMagick does not support WebP conversion
|
33 |
+
if (!in_array('WEBP', $im->queryFormats())) {
|
34 |
+
throw new ConverterNotOperationalException('iMagick was compiled without WebP support.');
|
35 |
+
}
|
36 |
+
|
37 |
+
$options = array_merge(ConverterHelper::$defaultOptions, $options);
|
38 |
+
|
39 |
+
// Force lossless option to true for PNG images
|
40 |
+
if (ConverterHelper::getExtension($source) == 'png') {
|
41 |
+
$options['lossless'] = true;
|
42 |
+
}
|
43 |
+
|
44 |
+
$im->setImageFormat('WEBP');
|
45 |
+
|
46 |
+
/*
|
47 |
+
* More about iMagick's WebP options:
|
48 |
+
* http://www.imagemagick.org/script/webp.php
|
49 |
+
* https://developers.google.com/speed/webp/docs/cwebp
|
50 |
+
* https://stackoverflow.com/questions/37711492/imagemagick-specific-webp-calls-in-php
|
51 |
+
*/
|
52 |
+
|
53 |
+
// TODO: We could easily support all webp options with a loop
|
54 |
+
$im->setOption('webp:method', strval($options['method']));
|
55 |
+
$im->setOption('webp:low-memory', strval($options['low-memory']));
|
56 |
+
$im->setOption('webp:lossless', strval($options['lossless']));
|
57 |
+
|
58 |
+
|
59 |
+
|
60 |
+
$im->setImageCompressionQuality($options['_calculated_quality']);
|
61 |
+
|
62 |
+
// TODO:
|
63 |
+
// Should we set alpha channel for PNG's like suggested here:
|
64 |
+
// https://gauntface.com/blog/2014/09/02/webp-support-with-imagemagick-and-php ??
|
65 |
+
// It seems that alpha channel works without... (at least I see completely transparerent pixels)
|
66 |
+
|
67 |
+
// TODO: Check out other iMagick methods, see http://php.net/manual/de/imagick.writeimage.php#114714
|
68 |
+
// 1. file_put_contents($destination, $im)
|
69 |
+
// 2. $im->writeImage($destination)
|
70 |
+
$success = $im->writeImageFile(fopen($destination, 'wb'));
|
71 |
+
|
72 |
+
if (!$success) {
|
73 |
+
throw new ConverterFailedException('Failed writing file');
|
74 |
+
}
|
75 |
+
}
|
76 |
+
}
|
vendor/webp-convert/Converters/Wpc.php
ADDED
@@ -0,0 +1,135 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace WebPConvert\Converters;
|
4 |
+
|
5 |
+
use WebPConvert\Converters\Exceptions\ConverterNotOperationalException;
|
6 |
+
use WebPConvert\Converters\Exceptions\ConverterFailedException;
|
7 |
+
|
8 |
+
class Wpc
|
9 |
+
{
|
10 |
+
public static $extraOptions = [
|
11 |
+
[
|
12 |
+
'name' => 'secret',
|
13 |
+
'type' => 'string',
|
14 |
+
'sensitive' => true,
|
15 |
+
'default' => 'my dog is white',
|
16 |
+
'required' => true
|
17 |
+
],
|
18 |
+
[
|
19 |
+
'name' => 'url',
|
20 |
+
'type' => 'string',
|
21 |
+
'sensitive' => true,
|
22 |
+
'default' => '',
|
23 |
+
'required' => true
|
24 |
+
],
|
25 |
+
];
|
26 |
+
|
27 |
+
public static function convert($source, $destination, $options = [])
|
28 |
+
{
|
29 |
+
ConverterHelper::runConverter('wpc', $source, $destination, $options, true);
|
30 |
+
}
|
31 |
+
|
32 |
+
// Although this method is public, do not call directly.
|
33 |
+
public static function doConvert($source, $destination, $options = [], $logger)
|
34 |
+
{
|
35 |
+
if ($options['url'] == '') {
|
36 |
+
throw new ConverterNotOperationalException('Missing URL. You must install WebpConvertCloudService on a server, and supply url');
|
37 |
+
}
|
38 |
+
|
39 |
+
if (!extension_loaded('curl')) {
|
40 |
+
throw new ConverterNotOperationalException('Required cURL extension is not available.');
|
41 |
+
}
|
42 |
+
|
43 |
+
if (!function_exists('curl_init')) {
|
44 |
+
throw new ConverterNotOperationalException('Required url_init() function is not available.');
|
45 |
+
}
|
46 |
+
|
47 |
+
if (!function_exists('curl_file_create')) {
|
48 |
+
throw new ConverterNotOperationalException('Required curl_file_create() function is not available (requires PHP > 5.5).');
|
49 |
+
}
|
50 |
+
|
51 |
+
// Got some code here:
|
52 |
+
// https://coderwall.com/p/v4ps1a/send-a-file-via-post-with-curl-and-php
|
53 |
+
|
54 |
+
$ch = curl_init();
|
55 |
+
if (!$ch) {
|
56 |
+
throw new ConverterNotOperationalException('Could not initialise cURL.');
|
57 |
+
}
|
58 |
+
|
59 |
+
$optionsToSend = $options;
|
60 |
+
|
61 |
+
if (isset($options['_quality_could_not_be_detected'])) {
|
62 |
+
// quality was set to "auto", but we could not meassure the quality of the jpeg locally
|
63 |
+
// Ask the cloud service to do it, rather than using what we came up with.
|
64 |
+
$optionsToSend['quality'] = 'auto';
|
65 |
+
} else {
|
66 |
+
$optionsToSend['quality'] = $options['_calculated_quality'];
|
67 |
+
}
|
68 |
+
|
69 |
+
unset($optionsToSend['converters']);
|
70 |
+
unset($optionsToSend['secret']);
|
71 |
+
unset($optionsToSend['_quality_could_not_be_detected']);
|
72 |
+
unset($optionsToSend['_calculated_quality']);
|
73 |
+
|
74 |
+
curl_setopt_array($ch, [
|
75 |
+
CURLOPT_URL => $options['url'],
|
76 |
+
CURLOPT_POST => 1,
|
77 |
+
CURLOPT_POSTFIELDS => [
|
78 |
+
'file' => curl_file_create($source),
|
79 |
+
'hash' => md5(md5_file($source) . $options['secret']),
|
80 |
+
'options' => json_encode($optionsToSend)
|
81 |
+
],
|
82 |
+
CURLOPT_BINARYTRANSFER => true,
|
83 |
+
CURLOPT_RETURNTRANSFER => true,
|
84 |
+
CURLOPT_HEADER => false,
|
85 |
+
CURLOPT_SSL_VERIFYPEER => false
|
86 |
+
]);
|
87 |
+
|
88 |
+
$response = curl_exec($ch);
|
89 |
+
|
90 |
+
if (curl_errno($ch)) {
|
91 |
+
throw new ConverterNotOperationalException(curl_error($ch));
|
92 |
+
}
|
93 |
+
|
94 |
+
// The WPC cloud service either returns an image or an error message
|
95 |
+
// Images has application/octet-stream.
|
96 |
+
|
97 |
+
// TODO: Check for 404 response, and handle that here
|
98 |
+
|
99 |
+
// Verify that we got an image back.
|
100 |
+
if (curl_getinfo($ch, CURLINFO_CONTENT_TYPE) != 'application/octet-stream') {
|
101 |
+
curl_close($ch);
|
102 |
+
throw new ConverterFailedException($response);
|
103 |
+
//throw new ConverterNotOperationalException($response);
|
104 |
+
}
|
105 |
+
|
106 |
+
$success = file_put_contents($destination, $response);
|
107 |
+
curl_close($ch);
|
108 |
+
|
109 |
+
if (!$success) {
|
110 |
+
throw new ConverterFailedException('Error saving file');
|
111 |
+
}
|
112 |
+
/*
|
113 |
+
$curlOptions = [
|
114 |
+
'api_key' => $options['key'],
|
115 |
+
'webp' => '1',
|
116 |
+
'file' => curl_file_create($source),
|
117 |
+
'domain' => $_SERVER['HTTP_HOST'],
|
118 |
+
'quality' => $options['quality'],
|
119 |
+
'metadata' => ($options['metadata'] == 'none' ? '0' : '1')
|
120 |
+
];
|
121 |
+
|
122 |
+
curl_setopt_array($ch, [
|
123 |
+
CURLOPT_URL => "https://optimize.exactlywww.com/v2/",
|
124 |
+
CURLOPT_HTTPHEADER => [
|
125 |
+
'User-Agent: WebPConvert',
|
126 |
+
'Accept: image/*'
|
127 |
+
],
|
128 |
+
CURLOPT_POSTFIELDS => $curlOptions,
|
129 |
+
CURLOPT_BINARYTRANSFER => true,
|
130 |
+
CURLOPT_RETURNTRANSFER => true,
|
131 |
+
CURLOPT_HEADER => false,
|
132 |
+
CURLOPT_SSL_VERIFYPEER => false
|
133 |
+
]);*/
|
134 |
+
}
|
135 |
+
}
|
vendor/webp-convert/Exceptions/ConverterNotFoundException.php
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace WebPConvert\Exceptions;
|
4 |
+
|
5 |
+
use WebPConvert\Exceptions\WebPConvertBaseException;
|
6 |
+
|
7 |
+
class ConverterNotFoundException extends WebPConvertBaseException
|
8 |
+
{
|
9 |
+
public $description = 'The converter does not exist.';
|
10 |
+
}
|
vendor/webp-convert/Exceptions/CreateDestinationFileException.php
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace WebPConvert\Exceptions;
|
4 |
+
|
5 |
+
use WebPConvert\Exceptions\WebPConvertBaseException;
|
6 |
+
|
7 |
+
class CreateDestinationFileException extends WebPConvertBaseException
|
8 |
+
{
|
9 |
+
public $description = 'The converter could not create destination file. Check file permisions!';
|
10 |
+
}
|
vendor/webp-convert/Exceptions/CreateDestinationFolderException.php
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace WebPConvert\Exceptions;
|
4 |
+
|
5 |
+
use WebPConvert\Exceptions\WebPConvertBaseException;
|
6 |
+
|
7 |
+
class CreateDestinationFolderException extends WebPConvertBaseException
|
8 |
+
{
|
9 |
+
public $description = 'The converter could not create destination folder. Check file permisions!';
|
10 |
+
}
|
vendor/webp-convert/Exceptions/InvalidFileExtensionException.php
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace WebPConvert\Exceptions;
|
4 |
+
|
5 |
+
use WebPConvert\Exceptions\WebPConvertBaseException;
|
6 |
+
|
7 |
+
class InvalidFileExtensionException extends WebPConvertBaseException
|
8 |
+
{
|
9 |
+
public $description = 'The converter does not accept the file extension';
|
10 |
+
}
|
vendor/webp-convert/Exceptions/TargetNotFoundException.php
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace WebPConvert\Exceptions;
|
4 |
+
|
5 |
+
use WebPConvert\Exceptions\WebPConvertBaseException;
|
6 |
+
|
7 |
+
class TargetNotFoundException extends WebPConvertBaseException
|
8 |
+
{
|
9 |
+
public $description = 'The converter could not locate source file';
|
10 |
+
}
|
vendor/webp-convert/Exceptions/WebPConvertBaseException.php
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace WebPConvert\Exceptions;
|
4 |
+
|
5 |
+
class WebPConvertBaseException extends \Exception
|
6 |
+
{
|
7 |
+
}
|
vendor/webp-convert/Loggers/BaseLogger.php
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace WebPConvert\Loggers;
|
4 |
+
|
5 |
+
abstract class BaseLogger
|
6 |
+
{
|
7 |
+
/*
|
8 |
+
$msg: message to log
|
9 |
+
$style: null | bold | italic
|
10 |
+
*/
|
11 |
+
abstract public function log($msg, $style = '');
|
12 |
+
|
13 |
+
abstract public function ln();
|
14 |
+
|
15 |
+
public function logLn($msg, $style = '')
|
16 |
+
{
|
17 |
+
$this->log($msg, $style);
|
18 |
+
$this->ln();
|
19 |
+
}
|
20 |
+
|
21 |
+
public function logLnLn($msg, $style = '')
|
22 |
+
{
|
23 |
+
$this->logLn($msg, $style);
|
24 |
+
$this->ln();
|
25 |
+
}
|
26 |
+
}
|
vendor/webp-convert/Loggers/EchoLogger.php
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace WebPConvert\Loggers;
|
4 |
+
|
5 |
+
class EchoLogger extends BaseLogger
|
6 |
+
{
|
7 |
+
public function log($msg, $style = '')
|
8 |
+
{
|
9 |
+
if ($style == 'bold') {
|
10 |
+
echo '<b>' . $msg . '</b>';
|
11 |
+
} elseif ($style == 'italic') {
|
12 |
+
echo '<i>' . $msg . '</i>';
|
13 |
+
} else {
|
14 |
+
echo $msg;
|
15 |
+
}
|
16 |
+
}
|
17 |
+
|
18 |
+
public function ln()
|
19 |
+
{
|
20 |
+
echo '<br>';
|
21 |
+
}
|
22 |
+
}
|
vendor/webp-convert/Loggers/VoidLogger.php
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace WebPConvert\Loggers;
|
4 |
+
|
5 |
+
class VoidLogger extends BaseLogger
|
6 |
+
{
|
7 |
+
public function log($msg, $style = '')
|
8 |
+
{
|
9 |
+
}
|
10 |
+
|
11 |
+
public function ln()
|
12 |
+
{
|
13 |
+
}
|
14 |
+
}
|
vendor/webp-convert/WebPConvert.php
ADDED
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace WebPConvert;
|
4 |
+
|
5 |
+
use WebPConvert\Converters\ConverterHelper;
|
6 |
+
|
7 |
+
class WebPConvert
|
8 |
+
{
|
9 |
+
|
10 |
+
/*
|
11 |
+
@param (string) $source: Absolute path to image to be converted (no backslashes). Image must be jpeg or png
|
12 |
+
@param (string) $destination: Absolute path (no backslashes)
|
13 |
+
@param (object) $options: Array of named options, such as 'quality' and 'metadata'
|
14 |
+
*/
|
15 |
+
public static function convert($source, $destination, $options = [], $logger = null)
|
16 |
+
{
|
17 |
+
if (!isset($logger)) {
|
18 |
+
$logger = new \WebPConvert\Loggers\VoidLogger();
|
19 |
+
}
|
20 |
+
ConverterHelper::prepareDestinationFolderAndRunCommonValidations($source, $destination);
|
21 |
+
|
22 |
+
$options = array_merge(ConverterHelper::$defaultOptions, $options);
|
23 |
+
|
24 |
+
ConverterHelper::processQualityOption($source, $options, $logger);
|
25 |
+
|
26 |
+
// Force lossless option to true for PNG images
|
27 |
+
if (ConverterHelper::getExtension($source) == 'png') {
|
28 |
+
$options['lossless'] = true;
|
29 |
+
}
|
30 |
+
|
31 |
+
$defaultConverterOptions = $options;
|
32 |
+
$defaultConverterOptions['converters'] = null;
|
33 |
+
|
34 |
+
$firstFailException = null;
|
35 |
+
|
36 |
+
foreach ($options['converters'] as $converter) {
|
37 |
+
if (is_array($converter)) {
|
38 |
+
$converterId = $converter['converter'];
|
39 |
+
$converterOptions = $converter['options'];
|
40 |
+
} else {
|
41 |
+
$converterId = $converter;
|
42 |
+
$converterOptions = [];
|
43 |
+
}
|
44 |
+
|
45 |
+
$converterOptions = array_merge($defaultConverterOptions, $converterOptions);
|
46 |
+
|
47 |
+
try {
|
48 |
+
$logger->logLn('Trying:' . $converterId, 'italic');
|
49 |
+
|
50 |
+
// If quality is different, we must recalculate
|
51 |
+
if ($converterOptions['quality'] != $defaultConverterOptions['quality']) {
|
52 |
+
unset($converterOptions['_calculated_quality']);
|
53 |
+
ConverterHelper::processQualityOption($source, $converterOptions, $logger);
|
54 |
+
}
|
55 |
+
|
56 |
+
ConverterHelper::runConverter($converterId, $source, $destination, $converterOptions, false, $logger);
|
57 |
+
|
58 |
+
// Still here? - well, we did it! - job is done.
|
59 |
+
$logger->logLn('ok', 'bold');
|
60 |
+
return true;
|
61 |
+
} catch (\WebPConvert\Converters\Exceptions\ConverterNotOperationalException $e) {
|
62 |
+
// $logger->logLnLn($e->description . ' : ' . $e->getMessage());
|
63 |
+
$logger->logLnLn($e->getMessage());
|
64 |
+
|
65 |
+
// The converter is not operational.
|
66 |
+
// Well, well, we will just have to try the next, then
|
67 |
+
} catch (\WebPConvert\Converters\Exceptions\ConverterFailedException $e) {
|
68 |
+
$logger->logLnLn($e->getMessage());
|
69 |
+
|
70 |
+
// Converter failed in an anticipated, yet somewhat surprising fashion.
|
71 |
+
// The converter seemed operational - requirements was in order - but it failed anyway.
|
72 |
+
// This is moderately bad.
|
73 |
+
// If some other converter can handle the conversion, we will let this one go.
|
74 |
+
// But if not, we shall throw the exception
|
75 |
+
|
76 |
+
if (!$firstFailException) {
|
77 |
+
$firstFailException = $e;
|
78 |
+
}
|
79 |
+
} catch (\WebPConvert\Converters\Exceptions\ConversionDeclinedException $e) {
|
80 |
+
$logger->logLnLn($e->getMessage());
|
81 |
+
|
82 |
+
// The converter declined.
|
83 |
+
// Gd is for example throwing this, when asked to convert a PNG, but configured not to
|
84 |
+
// We also possibly rethrow this, because it may have come as a surprise to the user
|
85 |
+
// who perhaps only tested jpg
|
86 |
+
if (!$firstFailException) {
|
87 |
+
$firstFailException = $e;
|
88 |
+
}
|
89 |
+
}
|
90 |
+
}
|
91 |
+
|
92 |
+
$logger->logLn('Conversion failed. None of the tried converters are operational', 'bold');
|
93 |
+
|
94 |
+
// No converters could do the job.
|
95 |
+
// If one of them failed moderately bad, rethrow that exception.
|
96 |
+
if ($firstFailException) {
|
97 |
+
throw $firstFailException;
|
98 |
+
}
|
99 |
+
|
100 |
+
return false;
|
101 |
+
}
|
102 |
+
}
|
vendor/webp-convert/autoload.php
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
function autoloadWebPConvert()
|
4 |
+
{
|
5 |
+
// load base classes, which are required for other classes
|
6 |
+
require_once(__DIR__ . '/Exceptions/WebPConvertBaseException.php');
|
7 |
+
require_once(__DIR__ . '/Loggers/BaseLogger.php');
|
8 |
+
|
9 |
+
$dirsToAutoload = [
|
10 |
+
'.',
|
11 |
+
'Converters',
|
12 |
+
'Exceptions',
|
13 |
+
'Converters/Exceptions',
|
14 |
+
'Loggers',
|
15 |
+
];
|
16 |
+
foreach ($dirsToAutoload as $dir) {
|
17 |
+
$dirAbs = __DIR__ . '/' . $dir;
|
18 |
+
|
19 |
+
// If directory has its own autoload.php, use that (but ignore autoload in current folder)
|
20 |
+
if ((file_exists($dirAbs . '/autoload.php') && ($dir != '.'))) {
|
21 |
+
require_once($dirAbs . '/autoload.php');
|
22 |
+
} else {
|
23 |
+
$files = glob($dirAbs . '/*.php');
|
24 |
+
foreach ($files as $file) {
|
25 |
+
// only require files that begins with uppercase (A-Z)
|
26 |
+
if (preg_match('/\/[A-Z][a-zA-Z]*\.php/', $file)) {
|
27 |
+
require_once($file);
|
28 |
+
}
|
29 |
+
}
|
30 |
+
}
|
31 |
+
}
|
32 |
+
}
|
33 |
+
autoloadWebPConvert();
|
vendor/webp-on-demand/PathHelper.php
ADDED
@@ -0,0 +1,170 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace WebPOnDemand;
|
4 |
+
|
5 |
+
class PathHelper
|
6 |
+
{
|
7 |
+
|
8 |
+
// Canonicalize a path by resolving '../' and './'
|
9 |
+
// Got it from a comment here: http://php.net/manual/en/function.realpath.php
|
10 |
+
// But fixed it (it could not handle './../')
|
11 |
+
public static function canonicalize($path)
|
12 |
+
{
|
13 |
+
$parts = explode('/', $path);
|
14 |
+
|
15 |
+
// Remove parts containing just '.' (and the empty holes afterwards)
|
16 |
+
$parts = array_values(array_filter($parts, function ($var) {
|
17 |
+
return ($var != '.');
|
18 |
+
}));
|
19 |
+
|
20 |
+
// Remove parts containing '..' and the preceding
|
21 |
+
$keys = array_keys($parts, '..');
|
22 |
+
foreach ($keys as $keypos => $key) {
|
23 |
+
array_splice($parts, $key - ($keypos * 2 + 1), 2);
|
24 |
+
}
|
25 |
+
return implode('/', $parts);
|
26 |
+
}
|
27 |
+
|
28 |
+
// We do not operate with backslashes here. Windows is a big boy now,
|
29 |
+
// it can handle forward slashes
|
30 |
+
public static function replaceBackslashes($str)
|
31 |
+
{
|
32 |
+
return str_replace('\\', '/', $str);
|
33 |
+
}
|
34 |
+
|
35 |
+
public static function removeDoubleSlash($str)
|
36 |
+
{
|
37 |
+
return preg_replace('/\/\//', '/', $str);
|
38 |
+
}
|
39 |
+
|
40 |
+
/* Get relative path between one dir and the other.
|
41 |
+
ie
|
42 |
+
from: /var/www/wordpress/wp-content/plugins/webp-express
|
43 |
+
to: /var/www/wordpress/wp-content/uploads
|
44 |
+
result: ../../uploads/
|
45 |
+
*/
|
46 |
+
public static function getRelDir($from_dir, $to_dir)
|
47 |
+
{
|
48 |
+
$fromDirParts = explode('/', str_replace('\\', '/', $from_dir));
|
49 |
+
$toDirParts = explode('/', str_replace('\\', '/', $to_dir));
|
50 |
+
$i = 0;
|
51 |
+
while (($i < count($fromDirParts)) && ($i < count($toDirParts)) && ($fromDirParts[$i] == $toDirParts[$i])) {
|
52 |
+
$i++;
|
53 |
+
}
|
54 |
+
$rel = "";
|
55 |
+
for ($j = $i; $j < count($fromDirParts); $j++) {
|
56 |
+
$rel .= "../";
|
57 |
+
}
|
58 |
+
|
59 |
+
for ($j = $i; $j < count($toDirParts); $j++) {
|
60 |
+
$rel .= $toDirParts[$j];
|
61 |
+
if ($j < count($toDirParts)-1) {
|
62 |
+
$rel .= '/';
|
63 |
+
}
|
64 |
+
}
|
65 |
+
return $rel;
|
66 |
+
}
|
67 |
+
|
68 |
+
// Strip filename from path
|
69 |
+
// Similar to dirname, but does not localize
|
70 |
+
public static function getFolder($path_with_filename) {
|
71 |
+
$parts = explode('/', $path_with_filename);
|
72 |
+
array_pop($parts);
|
73 |
+
return implode('/', $parts);
|
74 |
+
}
|
75 |
+
|
76 |
+
|
77 |
+
/**
|
78 |
+
* Calculates absolute path from relative path, but handles absolute path too
|
79 |
+
* Relative path is per default taken to be relative to DOCUMENT_ROOT.
|
80 |
+
* This can however be altered by providing another root
|
81 |
+
*
|
82 |
+
* If path starts with "/", it is considered an absolute path, and it is just
|
83 |
+
* passed through
|
84 |
+
*
|
85 |
+
* @param path Relative or absolute path (relative to document root).
|
86 |
+
*/
|
87 |
+
public static function abspath($relativeOrAbsolutePath, $root = null)
|
88 |
+
{
|
89 |
+
if (!isset($root)) {
|
90 |
+
$root = $_SERVER['DOCUMENT_ROOT'];
|
91 |
+
}
|
92 |
+
$relativeOrAbsolutePath = self::replaceBackslashes($relativeOrAbsolutePath);
|
93 |
+
if ((substr($relativeOrAbsolutePath, 0, 1) == '/')) {
|
94 |
+
return $relativeOrAbsolutePath;
|
95 |
+
} else {
|
96 |
+
return self::canonicalize(self::removeDoubleSlash($root . '/' . $relativeOrAbsolutePath));
|
97 |
+
}
|
98 |
+
}
|
99 |
+
|
100 |
+
/**
|
101 |
+
* Calculates relative path from absolute path, but handles absolute path too
|
102 |
+
* Relative path is per default taken to be relative to DOCUMENT_ROOT.
|
103 |
+
* This can however be altered by providing another root
|
104 |
+
*
|
105 |
+
* If path starts with "/", it is considered an absolute path, and it is just
|
106 |
+
* passed through
|
107 |
+
*
|
108 |
+
* @param path Relative or absolute path (relative to document root).
|
109 |
+
*/
|
110 |
+
public static function relpath($absPath, $root = null)
|
111 |
+
{
|
112 |
+
$absPath = self::abspath($absPath);
|
113 |
+
// self::logmsg('Source path: "' . $absPath . '"');
|
114 |
+
if (!isset($root)) {
|
115 |
+
$root = $_SERVER['DOCUMENT_ROOT'];
|
116 |
+
}
|
117 |
+
$source_rel = self::getRelDir($root, $absPath);
|
118 |
+
|
119 |
+
if (preg_match('/\.\.\//', $source_rel)) {
|
120 |
+
// self::logmsg('<b>Note</b>: path is outside document root. You are allowed to, but its unusual setup. When used to calculate destination folder, the "../"s will be removed');
|
121 |
+
}
|
122 |
+
return $source_rel;
|
123 |
+
}
|
124 |
+
|
125 |
+
/**
|
126 |
+
* Calculates absolute destination path
|
127 |
+
* Calculated like this : [desired destination root] + [relative path of source file] + ".webp"
|
128 |
+
*
|
129 |
+
* If you want converted files to be put in the same folder as the originals, just leave out
|
130 |
+
* the destination_root parameter.
|
131 |
+
*
|
132 |
+
* If you want all converted files to reside in their own folder, set the destination_root
|
133 |
+
* parameter to point to that folder. The converted files will be stored in a hierarchy that
|
134 |
+
* matches the source files. With destination_root set to "webp-cache", the source file
|
135 |
+
* "images/2017/cool.jpg" will be stored at "webp-cache/images/2017/cool.jpg.webp"
|
136 |
+
* You can provide absolute path or relative path for destination_root.
|
137 |
+
* If the path starts with "/", it is considered an absolute path (also true for source argument)
|
138 |
+
* Examples of valid paths "webp-cache", "/var/www/webp-cache", "..", "../images", "."
|
139 |
+
*
|
140 |
+
* @param source path to source file.
|
141 |
+
* May be absolute or relative (relative to document root or provided $root).
|
142 |
+
* @param destination_root path to destination root
|
143 |
+
*
|
144 |
+
* @return destination_path absolute path for destination file
|
145 |
+
*/
|
146 |
+
public static function getDestinationPath($source, $destination_root = '', $root = null)
|
147 |
+
{
|
148 |
+
|
149 |
+
if (!isset($root)) {
|
150 |
+
$root = $_SERVER['DOCUMENT_ROOT'];
|
151 |
+
}
|
152 |
+
|
153 |
+
// Step 1: Get relative path of source
|
154 |
+
$source_rel = self::relpath($source, $root);
|
155 |
+
|
156 |
+
// Step 2: Get absolute destination root
|
157 |
+
if ((substr($destination_root, 0, 1) == '/')) {
|
158 |
+
// Its already an absolute path. Do nothing
|
159 |
+
} else {
|
160 |
+
$destination_root = self::replaceBackslashes($destination_root);
|
161 |
+
if ($destination_root == '') {
|
162 |
+
$destination_root = '.';
|
163 |
+
}
|
164 |
+
$destination_root = self::canonicalize(self::removeDoubleSlash($root . '/' . $destination_root));
|
165 |
+
}
|
166 |
+
|
167 |
+
// Step 3: Put the two together, and append ".wepb"
|
168 |
+
return self::canonicalize(self::removeDoubleSlash($destination_root . '/' . preg_replace('/\.\.\//', '', $source_rel) . '.webp'));
|
169 |
+
}
|
170 |
+
}
|
vendor/webp-on-demand/WebPOnDemand.php
ADDED
@@ -0,0 +1,296 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
URL parameters:
|
4 |
+
|
5 |
+
source: Path to source file.
|
6 |
+
Can be absolute or relative to $root, that is passed in
|
7 |
+
If it starts with "/", it is considered an absolute path.
|
8 |
+
|
9 |
+
destination-root (optional):
|
10 |
+
The final destination will be calculated like this:
|
11 |
+
[destination-root] + [relative path of source file] + ".webp".
|
12 |
+
|
13 |
+
- Both absolute paths and relative paths are accepted (if the path starts with "/", it is considered an absolute
|
14 |
+
path).
|
15 |
+
- Double-dots in paths are allowed, ie "../webp-cache"
|
16 |
+
|
17 |
+
If you want converted files to be put in the same folder as the originals, you can set destination-root to ".", or
|
18 |
+
leave it blank. If you on the other hand want all converted files to reside in their own folder, set the
|
19 |
+
destination-root to point to that folder. The converted files will be stored in a hierarchy that matches the source
|
20 |
+
files. With destination-root set to "webp-cache", the source file "images/2017/cool.jpg" will be stored at
|
21 |
+
"webp-cache/images/2017/cool.jpg.webp".
|
22 |
+
|
23 |
+
quality (optional):
|
24 |
+
The quality of the generated WebP image, "auto" or 0-100. Defaults to "auto"
|
25 |
+
|
26 |
+
max-quality (optional):
|
27 |
+
The maximum quality. Only relevant when quality is set to "auto"
|
28 |
+
|
29 |
+
default-quality (optional):
|
30 |
+
Fallback value for quality, if it isn't possible to detect quality of jpeg. Only relevant when quality is set to "auto"
|
31 |
+
|
32 |
+
metadata (optional):
|
33 |
+
If set to "none", all metadata will be stripped
|
34 |
+
If set to "all", all metadata will be preserved
|
35 |
+
Note however that not all converters supports preserving metadata. cwebp supports it, imagewebp does not.
|
36 |
+
|
37 |
+
converters (optional):
|
38 |
+
Comma-separated list of converters. Ie. "cwebp,gd".
|
39 |
+
To pass options to the individual converters, see next.
|
40 |
+
Also, check out the WebPConvert docs
|
41 |
+
|
42 |
+
[converter-id]-[option-name] (optional):
|
43 |
+
This pattern is used for setting options on the individual converters.
|
44 |
+
Ie, in order to set the "key" option of the "ewww" converter, you pass "ewww-key".
|
45 |
+
|
46 |
+
[converter-id]-[n]-[option-name] (optional):
|
47 |
+
Use this pattern for targeting options of a converter, that are used multiple times. However, use the pattern above
|
48 |
+
for targeting the first occurence. `n` stands for the nth occurence of that converter in the `converters` option.
|
49 |
+
Example: `...&converters=cwebp,ewww,ewww,gd,ewww&ewww-key=xxx&ewww-2-key=yyy&ewww-3-key=zzz&gd-skip-pngs=1`
|
50 |
+
|
51 |
+
[converter-id]-[option-name]-[2] (optional):
|
52 |
+
This is an alternative, and simpler pattern than the above, for providing fallback for a single converter.
|
53 |
+
If WebPOnDemand detects that such an option is provided (ie ewww-key-2=yyy), it will automatically insert an extra
|
54 |
+
converter into the array (immidiately after), configured with the options with the '-2' postfix.
|
55 |
+
Example: `...&converters=cwebp,ewww,gd&ewww-key=xxx&ewww-key-2=yyy`
|
56 |
+
- will result in converter order: cwebp, ewww (with key=xxx), ewww (with key=yyy), gd
|
57 |
+
|
58 |
+
converters (optional):
|
59 |
+
Comma-separated list of converters. Ie. "cwebp,gd".
|
60 |
+
Passing options to the individual converters is done by passing options named like this:
|
61 |
+
[converter-name]-[option-name] (see below)
|
62 |
+
|
63 |
+
See WebPConvert documentation for more info
|
64 |
+
|
65 |
+
[converter]-[option-name] (optional):
|
66 |
+
Options for the converters can be passed as parameters with names like this: [converter]-[option-name].
|
67 |
+
Ie, in order to set the "key" option of the "ewww" converter, you pass "ewww-key".
|
68 |
+
|
69 |
+
If the same converter is going to be used with different configurations, you can add "-[n]" after the converter id.
|
70 |
+
Ie: ...&converters=ewww,ewww&ewww-key=xxx&ewww-2-key=yyy
|
71 |
+
|
72 |
+
See WebPConvert documentation for more info
|
73 |
+
|
74 |
+
debug (optional):
|
75 |
+
If set, a report will be served (as text) instead of an image
|
76 |
+
|
77 |
+
fail:
|
78 |
+
Default: "original"
|
79 |
+
What to serve if conversion fails
|
80 |
+
|
81 |
+
Possible values:
|
82 |
+
- "original": Serves the original image (source)
|
83 |
+
- "404": Serves a 404 header
|
84 |
+
- "report": Serves the error message as plain text
|
85 |
+
- "report-as-image": Serves the error message as an image
|
86 |
+
|
87 |
+
critical-fail:
|
88 |
+
Default: "report-as-image"
|
89 |
+
What to serve if conversion fails and source image is not available
|
90 |
+
|
91 |
+
Possible values:
|
92 |
+
- "404": Serves a 404 header
|
93 |
+
- "report": Serves the error message as plain text
|
94 |
+
- "report-as-image": Serves the error message as an image
|
95 |
+
|
96 |
+
*/
|
97 |
+
|
98 |
+
namespace WebPOnDemand;
|
99 |
+
|
100 |
+
use WebPConvertAndServe\WebPConvertAndServe;
|
101 |
+
use WebPConvert\WebPConvert;
|
102 |
+
use WebPOnDemand\PathHelper;
|
103 |
+
use WebPConvert\Converters\ConverterHelper;
|
104 |
+
|
105 |
+
class WebPOnDemand
|
106 |
+
{
|
107 |
+
private static function transformFallbackOptions($converters) {
|
108 |
+
foreach ($converters as $i => &$converter) {
|
109 |
+
$duplicateConverter = false;
|
110 |
+
foreach ($converter['options'] as $optionName => $optionValue) {
|
111 |
+
if (substr($optionName, -2) === '-2') {
|
112 |
+
$duplicateConverter = true;
|
113 |
+
break;
|
114 |
+
}
|
115 |
+
}
|
116 |
+
if ($duplicateConverter) {
|
117 |
+
$options2 = [];
|
118 |
+
foreach ($converter['options'] as $optionName => $optionValue) {
|
119 |
+
if (substr($optionName, -2) === '-2') {
|
120 |
+
$options2[substr($optionName, 0, -2)] = $optionValue;
|
121 |
+
unset($converter['options'][$optionName]);
|
122 |
+
}
|
123 |
+
}
|
124 |
+
array_splice($converters, $i+1, 0, [['converter' => $converter['converter'], 'options' => $options2]]);
|
125 |
+
}
|
126 |
+
}
|
127 |
+
return $converters;
|
128 |
+
}
|
129 |
+
|
130 |
+
private static function setOption(&$array, $parameterName, $optionName, $optionType)
|
131 |
+
{
|
132 |
+
if (!isset($_GET[$parameterName])) {
|
133 |
+
return;
|
134 |
+
}
|
135 |
+
switch ($optionType) {
|
136 |
+
case 'string':
|
137 |
+
//$options['converters'][$i]['options'][$optionName] = $_GET[$parameterName];
|
138 |
+
$array[$optionName] = $_GET[$parameterName];
|
139 |
+
break;
|
140 |
+
case 'boolean':
|
141 |
+
//$options['converters'][$i]['options'][$optionName] = ($_GET[$parameterName] == '1');
|
142 |
+
$array[$optionName] = ($_GET[$parameterName] == '1');
|
143 |
+
break;
|
144 |
+
}
|
145 |
+
}
|
146 |
+
public static function serve($root)
|
147 |
+
{
|
148 |
+
|
149 |
+
$debug = (isset($_GET['debug']) ? ($_GET['debug'] != 'no') : false);
|
150 |
+
|
151 |
+
//$source = $root . '/' . $_GET['source'];
|
152 |
+
$source = PathHelper::abspath($_GET['source'], $root);
|
153 |
+
|
154 |
+
$source = PathHelper::removeDoubleSlash($source);
|
155 |
+
|
156 |
+
|
157 |
+
if (isset($_GET['destination-root'])) {
|
158 |
+
$destination = PathHelper::getDestinationPath($source, $_GET['destination-root'], $root);
|
159 |
+
} else {
|
160 |
+
$destination = $source . '.webp';
|
161 |
+
}
|
162 |
+
|
163 |
+
$options = [];
|
164 |
+
|
165 |
+
// quality
|
166 |
+
if (isset($_GET['quality'])) {
|
167 |
+
if ($_GET['quality'] == 'auto') {
|
168 |
+
$options['quality'] = 'auto';
|
169 |
+
} else {
|
170 |
+
$options['quality'] = intval($_GET['quality']);
|
171 |
+
}
|
172 |
+
}
|
173 |
+
|
174 |
+
// max-quality
|
175 |
+
if (isset($_GET['max-quality'])) {
|
176 |
+
$options['max-quality'] = intval($_GET['max-quality']);
|
177 |
+
}
|
178 |
+
|
179 |
+
// default-quality
|
180 |
+
if (isset($_GET['default-quality'])) {
|
181 |
+
$options['default-quality'] = intval($_GET['default-quality']);
|
182 |
+
}
|
183 |
+
|
184 |
+
// method
|
185 |
+
if (isset($_GET['method'])) {
|
186 |
+
$options['method'] = $_GET['method'];
|
187 |
+
}
|
188 |
+
|
189 |
+
// metadata
|
190 |
+
if (isset($_GET['metadata'])) {
|
191 |
+
$options['metadata'] = $_GET['metadata'];
|
192 |
+
}
|
193 |
+
|
194 |
+
// converters
|
195 |
+
if (isset($_GET['converters'])) {
|
196 |
+
$conv = explode(',', $_GET['converters']);
|
197 |
+
$options['converters'] = [];
|
198 |
+
foreach ($conv as $i => $converter_name) {
|
199 |
+
$options['converters'][] = ['converter' => $converter_name, 'options' => []];
|
200 |
+
}
|
201 |
+
} else {
|
202 |
+
// Copy default converters.
|
203 |
+
// We need them in case some has options
|
204 |
+
foreach (ConverterHelper::$defaultOptions['converters'] as $i => $converter_name) {
|
205 |
+
$options['converters'][] = ['converter' => $converter_name, 'options' => []];
|
206 |
+
}
|
207 |
+
}
|
208 |
+
|
209 |
+
|
210 |
+
// Converter options
|
211 |
+
$counts = [];
|
212 |
+
foreach ($options['converters'] as $i => $converter_object) {
|
213 |
+
$converter = $converter_object['converter'];
|
214 |
+
//echo $i . ':' . $converter;
|
215 |
+
if (!isset($counts[$converter])) {
|
216 |
+
$counts[$converter] = 1;
|
217 |
+
$id = $converter;
|
218 |
+
}
|
219 |
+
else {
|
220 |
+
$counts[$converter]++;
|
221 |
+
}
|
222 |
+
|
223 |
+
$className = ConverterHelper::getClassNameOfConverter($converter);
|
224 |
+
$availOptions = array_column($className::$extraOptions, 'type', 'name');
|
225 |
+
//print_r($availOptions);
|
226 |
+
|
227 |
+
foreach ($availOptions as $optionName => $optionType) {
|
228 |
+
$parameterName = $converter . (($counts[$converter] > 1 ? '-' . $counts[$converter] : '')) . '-' . $optionName;
|
229 |
+
|
230 |
+
self::setOption($options['converters'][$i]['options'], $parameterName, $optionName, $optionType);
|
231 |
+
self::setOption($options['converters'][$i]['options'], $parameterName . '-2', $optionName . '-2', $optionType);
|
232 |
+
|
233 |
+
}
|
234 |
+
}
|
235 |
+
|
236 |
+
// transform options with '-2' postfix into new converters
|
237 |
+
$options['converters'] = self::transformFallbackOptions($options['converters']);
|
238 |
+
|
239 |
+
//echo '<pre>' . print_r($options, true) . '</pre>';
|
240 |
+
// Failure actions
|
241 |
+
$failCodes = [
|
242 |
+
"original" => WebPConvertAndServe::$ORIGINAL,
|
243 |
+
"404" => WebPConvertAndServe::$HTTP_404,
|
244 |
+
"report-as-image" => WebPConvertAndServe::$REPORT_AS_IMAGE,
|
245 |
+
"report" => WebPConvertAndServe::$REPORT,
|
246 |
+
];
|
247 |
+
|
248 |
+
$fail = 'original';
|
249 |
+
if (isset($_GET['fail'])) {
|
250 |
+
$fail = $_GET['fail'];
|
251 |
+
}
|
252 |
+
$fail = $failCodes[$fail];
|
253 |
+
|
254 |
+
$criticalFail = 'report';
|
255 |
+
if (isset($_GET['critical-fail'])) {
|
256 |
+
$criticalFail = $_GET['critical-fail'];
|
257 |
+
}
|
258 |
+
$criticalFail = $failCodes[$criticalFail];
|
259 |
+
|
260 |
+
if (!$debug) {
|
261 |
+
return WebPConvertAndServe::convertAndServeImage($source, $destination, $options, $fail, $criticalFail);
|
262 |
+
} else {
|
263 |
+
|
264 |
+
// TODO
|
265 |
+
// As we do not want to leak api keys, I have commented out the following.
|
266 |
+
/*
|
267 |
+
echo 'GET parameters:<br>';
|
268 |
+
foreach ($_GET as $key => $value) {
|
269 |
+
echo '<i>' . $key . '</i>: ' . htmlspecialchars($value) . '<br>';
|
270 |
+
}
|
271 |
+
echo '<br>';
|
272 |
+
*/
|
273 |
+
//echo $_SERVER['DOCUMENT_ROOT'];
|
274 |
+
WebPConvertAndServe::convertAndReport($source, $destination, $options);
|
275 |
+
return 1;
|
276 |
+
}
|
277 |
+
}
|
278 |
+
/*
|
279 |
+
$root = (
|
280 |
+
isset($_GET['root-folder']) ?
|
281 |
+
PathHelper::removeDoubleSlash($_SERVER['DOCUMENT_ROOT'] . '/' . $_GET['root-folder']) :
|
282 |
+
null
|
283 |
+
);*/
|
284 |
+
/*
|
285 |
+
destination (optional): (TODO)
|
286 |
+
Path to destination file. Can be absolute or relative (relative to document root).
|
287 |
+
You can choose not to specify destination. In that case, the path will be created based upon source,
|
288 |
+
destination-root and root-folder settings. If all these are blank, the destination will be same folder as source,
|
289 |
+
and the filename will have ".webp" appended to it (ie image.jpeg.webp)
|
290 |
+
|
291 |
+
root-folder (optional):
|
292 |
+
Usually, you will not need to supply anything. Might be relevant in rare occasions where the converter that
|
293 |
+
generates the URL cannot pass all of the relative path. For example, an .htaccess located in a subfolder may have
|
294 |
+
trouble passing the parent folders.*/
|
295 |
+
//$source = PathHelper::abspath($_GET['source'], $root);*/
|
296 |
+
}
|
vendor/webp-on-demand/autoload.php
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
function autoloadWebOnDemand()
|
4 |
+
{
|
5 |
+
$dirsToAutoload = [
|
6 |
+
'../webp-convert-and-serve',
|
7 |
+
'.',
|
8 |
+
];
|
9 |
+
foreach ($dirsToAutoload as $dir) {
|
10 |
+
$dirAbs = __DIR__ . '/' . $dir;
|
11 |
+
|
12 |
+
// If directory has its own autoload.php, use that (but ignore autoload in current folder)
|
13 |
+
if ((file_exists($dirAbs . '/autoload.php') && ($dir != '.'))) {
|
14 |
+
require_once($dirAbs . '/autoload.php');
|
15 |
+
} else {
|
16 |
+
$files = glob($dirAbs . '/*.php');
|
17 |
+
foreach ($files as $file) {
|
18 |
+
// only require files that begins with uppercase (A-Z)
|
19 |
+
if (preg_match('/\/[A-Z][a-zA-Z]*\.php/', $file)) {
|
20 |
+
require_once($file);
|
21 |
+
}
|
22 |
+
}
|
23 |
+
}
|
24 |
+
}
|
25 |
+
}
|
26 |
+
autoloadWebOnDemand();
|
webp-express.php
ADDED
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Plugin Name: WebP Express
|
4 |
+
* Plugin URI: https://github.com/rosell-dk/webp-express
|
5 |
+
* Description: Serve autogenerated WebP images instead of jpeg/png to browsers that supports WebP. Works on anything (media library images, galleries, theme images etc).
|
6 |
+
* Version: 0.1
|
7 |
+
* Author: Bjørn Rosell
|
8 |
+
* Author URI: https://www.bitwise-it.dk
|
9 |
+
* License: GPL2
|
10 |
+
*/
|
11 |
+
|
12 |
+
|
13 |
+
/*
|
14 |
+
Note: Perhaps create a plugin page on my website?, ie https://www.bitwise-it.dk/software/wordpress/webp-express
|
15 |
+
*/
|
16 |
+
|
17 |
+
define('WEBPEXPRESS_PLUGIN', __FILE__);
|
18 |
+
define('WEBPEXPRESS_PLUGIN_DIR', __DIR__);
|
19 |
+
|
20 |
+
add_action( 'admin_menu', function() {
|
21 |
+
|
22 |
+
//Add Settings Page
|
23 |
+
add_options_page(
|
24 |
+
'WebP Express Settings', //Page Title
|
25 |
+
__( 'WebP Express', 'yasr' ), //Menu Title
|
26 |
+
'manage_options', //capability
|
27 |
+
'webp_express_settings_page', //menu slug
|
28 |
+
'webp_express_settings_page_content' //The function to be called to output the content for this page.
|
29 |
+
);
|
30 |
+
});
|
31 |
+
|
32 |
+
include(plugin_dir_path(__FILE__) . 'lib/options.php');
|
33 |
+
|
34 |
+
if (get_option('webp-express-htaccess-needs-updating')) {
|
35 |
+
delete_option('webp-express-htaccess-needs-updating');
|
36 |
+
//include(plugin_dir_path(__FILE__) . 'lib/helpers.php');
|
37 |
+
include_once 'lib/helpers.php';
|
38 |
+
|
39 |
+
$rules = WebPExpressHelpers::generateHTAccessRules();
|
40 |
+
WebPExpressHelpers::insertHTAccessRules($rules);
|
41 |
+
|
42 |
+
}
|
43 |
+
|
44 |
+
|
45 |
+
register_activation_hook(__FILE__, function () {
|
46 |
+
include(plugin_dir_path(__FILE__) . 'lib/activate.php');
|
47 |
+
});
|
48 |
+
|
49 |
+
register_deactivation_hook(__FILE__, function () {
|
50 |
+
include(plugin_dir_path(__FILE__) . 'lib/deactivate.php');
|
51 |
+
});
|
52 |
+
|
53 |
+
if (get_option('webp-express-message-pending')) {
|
54 |
+
include(plugin_dir_path(__FILE__) . 'lib/message.php');
|
55 |
+
}
|
56 |
+
|
57 |
+
if (get_option('webp-express-deactivate')) {
|
58 |
+
add_action('admin_init', function () {
|
59 |
+
deactivate_plugins(plugin_basename(__FILE__));
|
60 |
+
});
|
61 |
+
delete_option('webp-express-deactivate');
|
62 |
+
}
|