';
133 | }
134 | }
135 |
--------------------------------------------------------------------------------
/changelog.txt:
--------------------------------------------------------------------------------
1 | = 2.8.7 =
2 | *Release Date = August 6, 2024*
3 |
4 | * added: change default permissions via imsanity_editor_permissions and imsanity_admin_permissions filters
5 | * changed: default permission to resize individual images changed to editor role
6 |
7 | = 2.8.6 =
8 | *Release Date - November 26, 2024*
9 |
10 | * fixed: fatal error if other plugins run big_image_size_threshold filter with too few arguments
11 |
12 | = 2.8.5 =
13 | *Release Date – November 26, 2024*
14 |
15 | * bumped WP tested version
16 | * changed: improve JSON handling/efficiency
17 |
18 | = 2.8.4 =
19 | *Release Date – April 29, 2024*
20 |
21 | * bumped WP tested version and PHP minimum
22 |
23 | = 2.8.3 =
24 | *Release Date – April 23, 2024*
25 |
26 | * changed: use updated WP coding standards
27 | * fixed: PHP 8 error trying to do math with string values
28 |
29 | = 2.8.2 =
30 | *Release Date – October 5, 2022*
31 |
32 | * fixed: mime type error when filename in attachment metadata is incorrect
33 |
34 | = 2.8.1 =
35 | *Release Date – June 16, 2022*
36 |
37 | * changed: escape and sanitize more things
38 | * changed: tighten PHPCS rules used for pre-release testing
39 |
40 | = 2.8.0 =
41 | *Release Date – May 18, 2022*
42 |
43 | * added: support for resizing WebP images via ImageMagick
44 | * changed: update attachment file size to keep WP 6.0 metadata in sync
45 | * changed: use original image for resizing if full size version was scaled by WordPress
46 | * fixed: JS scroller during bulk resize causes unexpected behavior
47 |
48 | = 2.7.2 =
49 | *Release Date – June 3, 2021*
50 |
51 | * fixed: delete originals might remove full-size version in rare cases
52 | * fixed: error thrown for image that is 1 pixel larger than max dimensions
53 |
54 | = 2.7.1 =
55 | *Release Date – November 24, 2020*
56 |
57 | * changed: clarify text for queue reset button
58 | * changed: Delete Originals function in bulk/selective resizer will clean metadata if original image is already gone
59 |
60 | = 2.7.0 =
61 | *Release Date – November 18, 2020*
62 |
63 | * changed: bulk resizer will resize all images with no limits, use list mode for selective resizing
64 | * added: see current dimensions and resize individual images in Media Library list mode
65 | * added: imsanity_disable_convert filter to bypass BMP/PNG to JPG conversion options conditionally
66 | * added: imsanity_skip_image filter to bypass resizing programmatically
67 | * added: ability to remove pre-scaled original image backup (in bulk or selectively)
68 | * changed: PNG images will not be converted if transparency is found
69 | * fixed: BMP files not converted when server uses image/x-ms-bmp as mime identifier
70 | * removed: Deep Scan option is the default behavior now, no need for configuration
71 |
72 | = 2.6.1 =
73 | * fixed: wrong parameter passed to imsanity_attachment_path()
74 |
75 | = 2.6.0 =
76 | * added: wp-cli command 'wp help imsanity resize'
77 | * fixed: adding an image to a post in pre-draft status uses wrong settings/dimensions
78 |
79 | = 2.5.0 =
80 | * added: imsanity_allowed_mimes filter to override the default list of image formats allowed
81 | * added: imsanity_orientation filter to modify auto-rotation behavior, return 1 to bypass
82 | * added: imsanity_get_max_width_height filter to customize max width/height
83 | * added: define network settings as defaults for new sites in multi-site mode
84 | * fixed: WP threshold of 2560 overrides Imsanity when using larger dimensions
85 | * fixed: settings link on plugins page broken in some cases
86 | * fixed: crop filter not applied if max width or height is equal to existing dimension
87 | * fixed: invalid capabilities used for settings page - props @cfoellmann
88 |
89 | = 2.4.3 =
90 | * changed: default size from 2048 to 1920
91 | * fixed: WP Import plugin breaks during Media imports
92 | * fixed: setting a value to 0 causes errors on multi-site installs
93 | * fixed: conversion settings not displaying correctly on multi-site
94 |
95 | = 2.4.2 =
96 | * changed: noresize in filename also works in batch processing
97 | * fixed: error message does not contain filename when file is missing
98 | * fixed: notice on network settings when deep scan option has not been set before
99 |
100 | = 2.4.1 =
101 | * fixed: bulk resizer scan returning incorrect results
102 | * fixed: sprintf error during resizing and upload
103 |
104 | = 2.4.0 =
105 | * added: deep scanning option for when attachment metadata isn't updating properly
106 | * fixed: uploads from Gutenberg not detected properly
107 | * fixed: some other plugin(s) trying to muck with the Imsanity settings links and breaking things
108 | * fixed: undefined notice for query during ajax operation
109 | * fixed: stale metadata could prevent further resizing
110 |
111 | = 2.3.9 =
112 | * fixed: PNG to JPG filled transparency with black instead of white
113 | * fixed: auto-rotation causes incorrect scaling
114 | * fixed: results box stops scrolling at line 28
115 | * added: pre-emptive checks on file parameter to prevent read errors with getimagesize()
116 |
117 | = 2.3.8 =
118 | * added: 'imsanity_crop_image' filter to crop images during resizing
119 | * added: increased security of network settings and AJAX requests
120 | * changed: metadata fetch and update use correct functions instead of direct database queries
121 | * changed: bulk resize search is kinder to your database
122 | * fixed: bulk resize could produce a larger image
123 | * fixed: image file permissions not checked prior to resizing
124 | * fixed: EWWW Image Optimizer optimizes image during resizing instead of waiting for metadata generation
125 | * fixed: JPG quality not displaying correctly on network/multisite settings page
126 | * fixed: some strings were not translatable
127 | * fixed: bulk resize results container was not scrollable
128 | * removed: legacy resize function for WP lower than 3.5
129 |
130 | = 2.3.7 =
131 | * fixed: uploads to Media Library not detected properly
132 | * changed: default JPG quality is now 82, to match the WordPress default
133 | * changed: fr_FR and ru_RU moved to WP.org language packs
134 | * changed: new maintainer
135 |
136 | = 2.3.6 =
137 | * tested up to WP 4.4
138 | * if resized image is not smaller than original, then keep original
139 | * allow IMSANITY_AJAX_MAX_RECORDS to be overridden in wp-config.php
140 | * if png-to-jpg is enabled, replace png transparency with white
141 |
142 | = 2.3.5 =
143 | * Add option to hide Imsanity girl logo image on settings screen
144 |
145 | = 2.3.4 =
146 | * Security update to network settings page
147 |
148 | = 2.3.3 =
149 | * Update default size from 1024 to 2048
150 | * Tested up to WordPress 4.1.1
151 | * Move screenshots to /assets folder
152 | * Added 256x256 icon
153 |
154 | = 2.3.2 =
155 | * Add PNG-To-JPG Option thanks to Jody Nesbitt
156 |
157 | = 2.3.1 =
158 | * ignore errors if EXIF data is not readable
159 | * show counter when bulk resizing images
160 |
161 | = 2.3.0 =
162 | * fix for incorrectly identifying media uploads as coming from 'other' on WP 4+
163 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Imsanity
2 |
3 | [](https://wordpress.org/plugins/imsanity/)
4 | [](https://wordpress.org/support/plugin/imsanity/reviews/)
5 | [](https://wordpress.org/plugins/imsanity/)
6 | [](https://wordpress.org/plugins/imsanity/)
7 | [](https://wordpress.org/plugins/imsanity/)
8 | [](https://wordpress.org/plugins/imsanity/)
9 | [](https://www.gnu.org/licenses/gpl-3.0.en.html)
10 |
11 | ## Description
12 |
13 | Automatically resize huge image uploads with Imsanity. Choose whatever size and quality you like, and let Imsanity do the rest. When a contributor uploads an image that is larger than the configured size, Imsanity will automatically scale it down to the configured size and replace the original image.
14 |
15 | Imsanity also provides a bulk-resize feature to resize previously uploaded images and free up disk space. You may resize individual images from the Media Library's List View.
16 |
17 | This plugin is ideal for blogs that do not require hi-resolution original images to be stored and/or the contributors don't want (or understand how) to scale images before uploading.
18 |
19 | You may report security issues through our Patchstack Vulnerability Disclosure Program. The Patchstack team helps validate, triage and handle any security vulnerabilities. [Report a security vulnerability.](https://patchstack.com/database/vdp/imsanity)
20 |
21 | ### Features
22 |
23 | * Automatically scales large image uploads to a more "sane" size
24 | * Bulk-resize feature to resize existing images
25 | * Selectively resize images directly in the Media Library (List View)
26 | * Allows configuration of max width/height and JPG quality
27 | * Optionally converts BMP and PNG files to JPG for more savings
28 | * Once enabled, Imsanity requires no actions on the part of the user
29 | * Uses WordPress built-in image scaling functions
30 |
31 | ### Translations
32 |
33 | Imsanity is available in several languages, each of which will be downloaded automatically when you install the plugin. To help translate it into your language, visit https://translate.wordpress.org/projects/wp-plugins/imsanity
34 |
35 | ## Installation
36 |
37 | ### Automatic Installation:
38 |
39 | 1. Go to Admin -> Plugins -> Add New and search for "imsanity"
40 | 1. Click the Install Button
41 | 1. Click 'Activate'
42 |
43 | ### Manual Installation:
44 |
45 | 1. Download imsanity.zip
46 | 1. Unzip and upload the 'imsanity' folder to your '/wp-content/plugins/' directory
47 | 1. Activate the plugin through the 'Plugins' menu in WordPress
48 |
49 | ## Frequently Asked Questions
50 |
51 | ### Will installing the Imsanity plugin alter existing images in my blog?
52 |
53 | Activating Imsanity will not alter any existing images. Imsanity resizes images as they are uploaded so it does not affect existing images unless you specifically use the "Bulk Image Resize" feature on the Imsanity settings page. The Bulk Resize feature allows you to quickly resize existing images.
54 |
55 | ### Why am I getting an error saying that my "File is not an image"?
56 |
57 | WordPress uses the GD library to handle the image manipulation. GD can be installed and configured to support various types of images. If GD is not configured to handle a particular image type then you will get this message when you try to upload it. For more info see http://php.net/manual/en/image.installation.php
58 |
59 | ### How can I tell Imsanity to ignore a certain image so I can upload it without being resized?
60 |
61 | You can re-name your file and add "-noresize" to the filename. For example if your file is named
62 | "photo.jpg" you can rename it "photo-noresize.jpg" and Imsanity will ignore it, allowing you
63 | to upload the full-sized image.
64 |
65 | If you are a developer (or have one handy), you can also use the 'imsanity_skip_image' filter to bypass resizing for any image.
66 |
67 | ### Does Imsanity compress or optimize my images?
68 |
69 | While Imsanity does compress JPG images in the process of resizing them, it uses the standard WordPress compression. Thus, the resulting images are not efficiently encoded and can be optimized further (without quality loss) by the EWWW Image Optimizer and many other image optimization plugins.
70 |
71 | ### Will Imsanity resize images from plugin X, Y, or Z?
72 |
73 | If the images can be found in the Media Library of your site, then it is likely Imsanity will resize them. Imsanity uses the wp_handle_upload hook to process new uploads and can resize any existing images in the Media Library using the Bulk Resizer. If the images are not in the Media Library, you can use the EWWW Image Optimizer to resize them.
74 |
75 | ### Why would I need this plugin?
76 |
77 | Photos taken on any modern camera and most cellphones are too large to display full-size in a browser.
78 | This wastes space on your web server, and wastes bandwidth for your visitors to view these files.
79 |
80 | Imsanity allows you to set a sanity limit so that all uploaded images will be constrained to a reasonable size which is still more than large enough for the needs of a typical website. Imsanity hooks into WordPress immediately after the image upload, but before WordPress processing occurs. So WordPress behaves exactly the same in all ways, except it will be as if the contributor had scaled their image to a reasonable size before uploading.
81 |
82 | The size limit that imsanity uses is configurable. The default value is large enough to fill the average vistor's entire screen without scaling so it is still more than large enough for typical usage.
83 |
84 | ### Why would I NOT want to use this plugin?
85 |
86 | You might not want to use Imsanity if you use WordPress as a stock art download site, to provide hi-resolution images for print or use WordPress as a hi-resolution photo storage archive.
87 |
88 | ### Doesn't WordPress already automatically scale images?
89 |
90 | When an image is uploaded WordPress keeps the original and, depending on the size of the original, will create up to 4 smaller sized copies of the file (Large, Medium-Large, Medium, Thumbnail) which are intended for embedding on your pages. Unless you have special photographic needs, the original usually sits there unused, but taking up disk quota.
91 |
92 | ### Why did you spell Insanity wrong?
93 |
94 | Imsanity is short for "Image Sanity Limit". A sanity limit is a term for limiting something down to
95 | a size or value that is reasonable.
96 |
97 | ### Where do I go for support?
98 |
99 | Questions may be posted on the support forum at https://wordpress.org/support/plugin/imsanity but if you don't get an answer, please use https://ewww.io/contact-us/.
100 |
101 | ## Credits
102 |
103 | Originally written by Jason Hinkle (RIP). Maintained and developed by [Shane Bishop](https://ewww.io) with special thanks to my [Lord and Savior](https://www.iamsecond.com/).
104 |
--------------------------------------------------------------------------------
/languages/imsanity-sv_SE.po:
--------------------------------------------------------------------------------
1 | # Translation of Plugins - Imsanity - Development (trunk) in Swedish
2 | # This file is distributed under the same license as the Plugins - Imsanity - Development (trunk) package.
3 | msgid ""
4 | msgstr ""
5 | "PO-Revision-Date: 2015-09-23 14:53:56+0000\n"
6 | "MIME-Version: 1.0\n"
7 | "Content-Type: text/plain; charset=UTF-8\n"
8 | "Content-Transfer-Encoding: 8bit\n"
9 | "Plural-Forms: nplurals=2; plural=n != 1;\n"
10 | "X-Generator: GlotPress/2.3.0-alpha\n"
11 | "Language: sv_SE\n"
12 | "Project-Id-Version: Plugins - Imsanity - Development (trunk)\n"
13 |
14 | #. Author URI of the plugin/theme
15 | msgid "http://verysimple.com/"
16 | msgstr ""
17 |
18 | #. Author of the plugin/theme
19 | msgid "Jason Hinkle"
20 | msgstr ""
21 |
22 | #. Description of the plugin/theme
23 | msgid "Imsanity stops insanely huge image uploads"
24 | msgstr ""
25 |
26 | #. Plugin URI of the plugin/theme
27 | msgid "http://verysimple.com/products/imsanity/"
28 | msgstr ""
29 |
30 | #. Plugin Name of the plugin/theme
31 | msgid "Imsanity"
32 | msgstr ""
33 |
34 | #: settings.php:628
35 | msgid "Save Changes"
36 | msgstr "Spara Ändringar"
37 |
38 | #: settings.php:619
39 | msgid "Convert PNG To JPG"
40 | msgstr ""
41 |
42 | #: settings.php:611
43 | msgid "Convert BMP To JPG"
44 | msgstr "Konvertera BMP till JPG"
45 |
46 | #: settings.php:597
47 | msgid "JPG image quality"
48 | msgstr "Bildkvalitet för JPG"
49 |
50 | #: settings.php:556
51 | msgid "Imsanity settings have been configured by the server administrator. There are no site-specific settings available."
52 | msgstr "Imsanitys inställningar har konfigurerats av serveradministratören. Det finns inga webbplatsspecifika inställningar tillgängliga."
53 |
54 | #: settings.php:539
55 | msgid "Search Images..."
56 | msgstr "Sök Bilder..."
57 |
58 | #: settings.php:532
59 | msgid ""
60 | "It is HIGHLY recommended that you backup \n"
61 | "\t\tyour wp-content/uploads folder before proceeding. You will have a chance to preview and select the images to convert.\n"
62 | "\t\tIt is also recommended that you initially select only 1 or 2 images and verify that everything is ok before\n"
63 | "\t\tprocessing your entire library. You have been warned!"
64 | msgstr ""
65 | "Du rekommenderas STARKT att ta backup på \n"
66 | "\t\tdin wp-content/uploads mapp innan du fortsätter. Du kommer att få möjlighet att förhandsvisa och välja bilder att konvertera.\n"
67 | "\t\tDu rekommenderas också att först prova med 1 eller 2 bilder och kontrollera att all är ok innan\n"
68 | "\t\tdu processar hela mediabiblioteket. Du har blivit varnad!"
69 |
70 | #: settings.php:530
71 | msgid "WARNING: BULK RESIZE WILL ALTER YOUR ORIGINAL IMAGES AND CANNOT BE UNDONE!"
72 | msgstr "VARNING: BULKSKALNING KOMMER ATT ÄNDRA ORIGINALBILDERNA OCH KAN INTE ÅNGRAS!"
73 |
74 | #: settings.php:519
75 | msgid "Bulk Resize Images"
76 | msgstr "Bulkskala Bilder"
77 |
78 | #: settings.php:501
79 | msgid "Imsanity Settings"
80 | msgstr "Imsanity Inställningar"
81 |
82 | #: settings.php:484
83 | msgid "
Imsanity automaticaly reduces the size of images that are larger than the specified maximum and replaces the original\n"
89 | "\t\twith one of a more \"sane\" size. Site contributors don\\'t need to concern themselves with manually scaling images\n"
90 | "\t\tand can upload them directly from their camera or phone.
\n"
91 | "\n"
92 | "\t\t
The resolution of modern cameras is larger than necessary for typical web display.\n"
93 | "\t\tThe average computer screen is not big enough to display a 3 megapixel camera-phone image at full resolution.\n"
94 | "\t\tWordPress does a good job of creating scaled-down copies which can be used, however the original images\n"
95 | "\t\tare permanently stored, taking up disk quota and, if used on a page, create a poor viewer experience.
\n"
96 | "\n"
97 | "\t\t
This plugin is designed for sites where high-resolution images are not necessary and/or site contributors\n"
98 | "\t\tdo not want (or understand how) to deal with scaling images. This plugin should not be used on\n"
99 | "\t\tsites for which original, high-resolution images must be stored.
\n"
100 | "\n"
101 | "\t\t
Be sure to save back-ups of your full-sized images if you wish to keep them.
"
102 | msgstr ""
103 | "
Imsanity reducerar automatiskt storleken på bilder som är större än den specificerade maxstorleken och ersätter originalet\n"
104 | "\t\tmed en version som har en mer \"sund\" storlek. Webbplatsmedarbetare behöver inte bekymra sig om att manuellt skala bilder\n"
105 | "\t\toch kan ladda upp dem direkt från sin kamera eller mobil.
\n"
106 | "\n"
107 | "\t\t
Upplösningen på moderna kameror är högre än nödvändigt för vanlig webbvisning.\n"
108 | "\t\tDen genomsnittliga datorskärmen är inte stor nog att visa en 3 megapixels bild från kamera/telefon i full upplösning.\n"
109 | "\t\tWordPress gör ett bra jobb med att skapa nedskalade kopior som kan användas, men originalbilderna\n"
110 | "\t\tlagras permanent och upptar diskutrymme och skapar en dålig visuell upplevelse för besökaren om de används på en sida.
\n"
111 | "\n"
112 | "\t\t
Detta insticksprogram är designat för webbplatser där högupplösta bilder inte är nödvändiga och/eller webbplatsmedarbetare\n"
113 | "\t\tinte vill (eller kan) skala bilder. Detta insticksprogram bör inte användas på\n"
114 | "\t\twebbplatser där högupplösta bildoriginal måste lagras.
\n"
115 | "\n"
116 | "\t\t
Se till att spara kopior av dina bildoriginal i full storlek om du vill behålla dem.
"
117 |
118 | #: settings.php:467
119 | msgid "Imsanity automatically resizes insanely huge image uploads"
120 | msgstr "Imsanity förminskar automatiskt uppladdade bilder som är galet stora"
121 |
122 | #: settings.php:286
123 | msgid "Update Settings"
124 | msgstr "Uppdatera Inställningar"
125 |
126 | #: settings.php:281 settings.php:607
127 | msgid " (WordPress default is 90)"
128 | msgstr " (Wordpress standardinställning är 90)"
129 |
130 | #: settings.php:271
131 | msgid "JPG Quality"
132 | msgstr "JPG-kvalitet"
133 |
134 | #: settings.php:263
135 | msgid "Convert PNG to JPG"
136 | msgstr ""
137 |
138 | #: settings.php:258 settings.php:266 settings.php:614 settings.php:622
139 | msgid "No"
140 | msgstr "Nej"
141 |
142 | #: settings.php:257 settings.php:265 settings.php:613 settings.php:621
143 | msgid "Yes"
144 | msgstr "Ja"
145 |
146 | #: settings.php:255
147 | msgid "Convert BMP to JPG"
148 | msgstr "Konvertera BMP till JPG"
149 |
150 | #: settings.php:247 settings.php:589
151 | msgid "Images uploaded elsewhere (Theme headers, backgrounds, logos, etc)"
152 | msgstr "Bilder uppladdade på andra ställen (Sidhuvud för teman, bakgrunder, logotyper, etc.)"
153 |
154 | #: settings.php:239 settings.php:582
155 | msgid "Images uploaded directly to the Media Library"
156 | msgstr "Bilder uppladdade direkt till Mediabiblioteket"
157 |
158 | #: settings.php:234 settings.php:242 settings.php:250 settings.php:577
159 | #: settings.php:584 settings.php:591
160 | msgid " (or enter 0 to disable)"
161 | msgstr "(eller ange 0 för att deaktivera)"
162 |
163 | #: settings.php:231 settings.php:575
164 | msgid "Images uploaded within a Page/Post"
165 | msgstr "Bilder uppladdade till en Sida/Inlägg"
166 |
167 | #: settings.php:225
168 | msgid "Use global Imsanity settings (below) for all sites"
169 | msgstr "Använd Imsanitys globala inställningar (nedan) för alla webbplatser"
170 |
171 | #: settings.php:224
172 | msgid "Allow each site to configure Imsanity settings"
173 | msgstr "Tillåt varje webbplats att konfigurera Imsanitys inställningar"
174 |
175 | #: settings.php:221
176 | msgid "Global Settings Override"
177 | msgstr "Åsidosätt Globala Inställningar"
178 |
179 | #: settings.php:207
180 | msgid "Imsanity network settings saved."
181 | msgstr "Imsanity nätverksinställningar sparades."
182 |
183 | #: settings.php:187 settings.php:200
184 | msgid "Imsanity Network Settings"
185 | msgstr "Imsanity Nätverksinställningar"
186 |
187 | #: settings.php:40
188 | msgid "Imsanity Plugin Settings"
189 | msgstr "Imsanity Programinställningar"
190 |
191 | #: libs/imagecreatefrombmp.php:129
192 | msgid "imagecreatefrombmp: %s has %d bits and this is not supported!"
193 | msgstr "imagecreatefrombmp: %s har %d bits vilket inte stöds!"
194 |
195 | #: libs/imagecreatefrombmp.php:43
196 | msgid "imagecreatefrombmp: Can not obtain filesize of %s !"
197 | msgstr "imagecreatefrombmp: Kan inte hämta filstorlek %s!"
198 |
199 | #: libs/imagecreatefrombmp.php:21
200 | msgid "imagecreatefrombmp: %s is not a bitmap!"
201 | msgstr "imagecreatefrombmp: %s är ingen bitmap!"
202 |
203 | #: libs/imagecreatefrombmp.php:14
204 | msgid "imagecreatefrombmp: Can not open %s!"
205 | msgstr "imagecreatefrombmp: Kan inte öppna %s !"
206 |
207 | #: ajax.php:185
208 | msgid "ERROR: (Attachment with ID of %s not found) "
209 | msgstr "FEL: (Bilaga med ID %s hittades ej) "
210 |
211 | #: ajax.php:179
212 | msgid "SKIPPED: %s (Resize not required)"
213 | msgstr "HOPPADE ÖVER: %s (Storleksändring behövs ej)"
214 |
215 | #: ajax.php:174
216 | msgid "ERROR: %s (%s)"
217 | msgstr "FEL: %s (%s)"
218 |
219 | #: ajax.php:170
220 | msgid "OK: %s"
221 | msgstr "OK: %s"
222 |
223 | #: ajax.php:98
224 | msgid "Missing ID Parameter"
225 | msgstr "Saknad ID-parameter"
--------------------------------------------------------------------------------
/languages/imsanity-es_MX.po:
--------------------------------------------------------------------------------
1 | # Translation of Plugins - Imsanity - Development (trunk) in Spanish (Mexico)
2 | # This file is distributed under the same license as the Plugins - Imsanity - Development (trunk) package.
3 | msgid ""
4 | msgstr ""
5 | "PO-Revision-Date: 2015-12-08 16:01:42+0000\n"
6 | "MIME-Version: 1.0\n"
7 | "Content-Type: text/plain; charset=UTF-8\n"
8 | "Content-Transfer-Encoding: 8bit\n"
9 | "Plural-Forms: nplurals=2; plural=n != 1;\n"
10 | "X-Generator: GlotPress/2.3.0-alpha\n"
11 | "Language: es_MX\n"
12 | "Project-Id-Version: Plugins - Imsanity - Development (trunk)\n"
13 |
14 | #. Author URI of the plugin/theme
15 | msgid "http://verysimple.com/"
16 | msgstr ""
17 |
18 | #. Author of the plugin/theme
19 | msgid "Jason Hinkle"
20 | msgstr ""
21 |
22 | #. Description of the plugin/theme
23 | msgid "Imsanity stops insanely huge image uploads"
24 | msgstr ""
25 |
26 | #. Plugin URI of the plugin/theme
27 | msgid "http://verysimple.com/products/imsanity/"
28 | msgstr ""
29 |
30 | #. Plugin Name of the plugin/theme
31 | msgid "Imsanity"
32 | msgstr ""
33 |
34 | #: settings.php:628
35 | msgid "Save Changes"
36 | msgstr "Guardar Cambios"
37 |
38 | #: settings.php:619
39 | msgid "Convert PNG To JPG"
40 | msgstr ""
41 |
42 | #: settings.php:611
43 | msgid "Convert BMP To JPG"
44 | msgstr "Convertir BMP a JPG"
45 |
46 | #: settings.php:597
47 | msgid "JPG image quality"
48 | msgstr "Calidad de imagen JPG"
49 |
50 | #: settings.php:556
51 | msgid "Imsanity settings have been configured by the server administrator. There are no site-specific settings available."
52 | msgstr "Configuración de Imsanity se han configurado por el administrador del servidor. No se dispone de ninguna configuración específica."
53 |
54 | #: settings.php:539
55 | msgid "Search Images..."
56 | msgstr "Búsqueda de imágenes..."
57 |
58 | #: settings.php:532
59 | msgid ""
60 | "It is HIGHLY recommended that you backup \n"
61 | "\t\tyour wp-content/uploads folder before proceeding. You will have a chance to preview and select the images to convert.\n"
62 | "\t\tIt is also recommended that you initially select only 1 or 2 images and verify that everything is ok before\n"
63 | "\t\tprocessing your entire library. You have been warned!"
64 | msgstr ""
65 | "Importante! Es recomendable que realizar el backup de carpeta wp-content/uploads \\\t\\\tyour antes de proceder. Usted tendrá la oportunidad de escuchar y seleccionar las imágenes a convertir.\n"
66 | "\\\t\\\tIt también se recomienda que inicialmente seleccionar sólo 1 ó 2 imágenes y comprobar que todo está bien antes de \\\t\\\tprocessing la biblioteca entera. Estáis avisados."
67 |
68 | #: settings.php:530
69 | msgid "WARNING: BULK RESIZE WILL ALTER YOUR ORIGINAL IMAGES AND CANNOT BE UNDONE!"
70 | msgstr "ADVERTENCIA: A GRANEL RESIZE ALTERARÁ SUS IMÁGENES ORIGINALES Y NO SE PUEDE DESHACER!"
71 |
72 | #: settings.php:519
73 | msgid "Bulk Resize Images"
74 | msgstr "A granel redimensionar imágenes"
75 |
76 | #: settings.php:501
77 | msgid "Imsanity Settings"
78 | msgstr "Configuración de Imsanity"
79 |
80 | #: settings.php:484
81 | msgid "
Imsanity automaticaly reduces the size of images that are larger than the specified maximum and replaces the original\n"
87 | "\t\twith one of a more \"sane\" size. Site contributors don\\'t need to concern themselves with manually scaling images\n"
88 | "\t\tand can upload them directly from their camera or phone.
\n"
89 | "\n"
90 | "\t\t
The resolution of modern cameras is larger than necessary for typical web display.\n"
91 | "\t\tThe average computer screen is not big enough to display a 3 megapixel camera-phone image at full resolution.\n"
92 | "\t\tWordPress does a good job of creating scaled-down copies which can be used, however the original images\n"
93 | "\t\tare permanently stored, taking up disk quota and, if used on a page, create a poor viewer experience.
\n"
94 | "\n"
95 | "\t\t
This plugin is designed for sites where high-resolution images are not necessary and/or site contributors\n"
96 | "\t\tdo not want (or understand how) to deal with scaling images. This plugin should not be used on\n"
97 | "\t\tsites for which original, high-resolution images must be stored.
\n"
98 | "\n"
99 | "\t\t
Be sure to save back-ups of your full-sized images if you wish to keep them.
"
100 | msgstr ""
101 | "
Imsanity reduce de forma automática el tamaño de las imágenes que son más grandes que el máximo especificado y sustituye al original\n"
102 | "\\\t\\\twith uno de un tamaño más\"sano\" . Colaboradores del sitio don\\'t tiene que preocuparse por la ampliación de imágenes manualmente\n"
103 | "\\\t\\\tand puede cargar directamente desde su cámara o teléfono . < / P>\n"
104 | "\n"
105 | "\\\t\\\t
La resolución de las cámaras modernas es más grande de lo necesario para la visualización web típica .\n"
106 | "\\\t\\pantalla media lLa no es lo suficientemente grande como para mostrar una imagen de la cámara - teléfono 3 megapíxeles con la máxima resolución .\n"
107 | "\\\t\\\tWordPress hace un buen trabajo de crear a escala reducida copias que se pueden utilizar , sin embargo, las imágenes originales\n"
108 | "\\\t\\\tara almacenado de forma permanente , tomando cuota de disco y , si se utiliza en una página, crear una experiencia pobre espectador. < / p>\n"
109 | "\n"
110 | "\\\t\\\t < p> Este plugin está diseñado para los sitios donde las imágenes de alta resolución no son necesarios y / o sitio contribuyentes\n"
111 | "\\\t\\\tno quieren ( o entender cómo) para hacer frente a las imágenes de escala. Este complemento no se debe utilizar en\n"
112 | "\\\t\\\tsites para que las imágenes originales de alta resolución deben ser almacenados .
\n"
113 | "\n"
114 | "\\\t\\\t
Asegúrese de guardar copias de seguridad de toda su imágenes de tamaño si lo desea para mantenerlos .
"
115 |
116 | #: settings.php:467
117 | msgid "Imsanity automatically resizes insanely huge image uploads"
118 | msgstr "Automáticamente cambia el tamaño de imagen enorme subidas"
119 |
120 | #: settings.php:286
121 | msgid "Update Settings"
122 | msgstr "Configuración de actualización"
123 |
124 | #: settings.php:281 settings.php:607
125 | msgid " (WordPress default is 90)"
126 | msgstr " (Por defecto de WordPress es 90)"
127 |
128 | #: settings.php:271
129 | msgid "JPG Quality"
130 | msgstr "Calidad JPG"
131 |
132 | #: settings.php:263
133 | msgid "Convert PNG to JPG"
134 | msgstr ""
135 |
136 | #: settings.php:258 settings.php:266 settings.php:614 settings.php:622
137 | msgid "No"
138 | msgstr "No"
139 |
140 | #: settings.php:257 settings.php:265 settings.php:613 settings.php:621
141 | msgid "Yes"
142 | msgstr "Si"
143 |
144 | #: settings.php:255
145 | msgid "Convert BMP to JPG"
146 | msgstr "Convertir BMP a JPG"
147 |
148 | #: settings.php:247 settings.php:589
149 | msgid "Images uploaded elsewhere (Theme headers, backgrounds, logos, etc)"
150 | msgstr "Imágenes subidas en otros lugares (tema cabeceras, fondos, logotipos, etc.)"
151 |
152 | #: settings.php:239 settings.php:582
153 | msgid "Images uploaded directly to the Media Library"
154 | msgstr "Imágenes subidas directamente a la biblioteca multimedia"
155 |
156 | #: settings.php:234 settings.php:242 settings.php:250 settings.php:577
157 | #: settings.php:584 settings.php:591
158 | msgid " (or enter 0 to disable)"
159 | msgstr " (o escriba 0 para desactivar)"
160 |
161 | #: settings.php:231 settings.php:575
162 | msgid "Images uploaded within a Page/Post"
163 | msgstr "Imágenes subidas dentro de un página y Post"
164 |
165 | #: settings.php:225
166 | msgid "Use global Imsanity settings (below) for all sites"
167 | msgstr "Utilice la configuración global Imsanity (abajo) para todos los sitios"
168 |
169 | #: settings.php:224
170 | msgid "Allow each site to configure Imsanity settings"
171 | msgstr "Permitir que cada sitio configurar las opciones de Imsanity"
172 |
173 | #: settings.php:221
174 | msgid "Global Settings Override"
175 | msgstr "Anulación de la configuración global"
176 |
177 | #: settings.php:207
178 | msgid "Imsanity network settings saved."
179 | msgstr "Configuración de red Imsanity guardado."
180 |
181 | #: settings.php:187 settings.php:200
182 | msgid "Imsanity Network Settings"
183 | msgstr "Configuración de red Imsanity"
184 |
185 | #: settings.php:40
186 | msgid "Imsanity Plugin Settings"
187 | msgstr "Configuración de Imsanity"
188 |
189 | #: libs/imagecreatefrombmp.php:129
190 | msgid "imagecreatefrombmp: %s has %d bits and this is not supported!"
191 | msgstr "imagecreatefrombmp: %s tiene %d bits y esto no es compatible."
192 |
193 | #: libs/imagecreatefrombmp.php:43
194 | msgid "imagecreatefrombmp: Can not obtain filesize of %s !"
195 | msgstr "imagecreatefrombmp: no puede obtener tamaño de %s!"
196 |
197 | #: libs/imagecreatefrombmp.php:21
198 | msgid "imagecreatefrombmp: %s is not a bitmap!"
199 | msgstr "imagecreatefrombmp: %s no es un mapa de bits."
200 |
201 | #: libs/imagecreatefrombmp.php:14
202 | msgid "imagecreatefrombmp: Can not open %s!"
203 | msgstr "imagecreatefrombmp: no se puede abrir %s!"
204 |
205 | #: ajax.php:185
206 | msgid "ERROR: (Attachment with ID of %s not found) "
207 | msgstr "ERROR: (Adjunto con el ID de %s no encontrado) "
208 |
209 | #: ajax.php:179
210 | msgid "SKIPPED: %s (Resize not required)"
211 | msgstr "OMITIDOS: %s (no es necesario redimensionar)"
212 |
213 | #: ajax.php:174
214 | msgid "ERROR: %s (%s)"
215 | msgstr "ERROR: %s (%s)"
216 |
217 | #: ajax.php:170
218 | msgid "OK: %s"
219 | msgstr "Bueno %s"
220 |
221 | #: ajax.php:98
222 | msgid "Missing ID Parameter"
223 | msgstr "Falta el parámetro ID"
--------------------------------------------------------------------------------
/readme.txt:
--------------------------------------------------------------------------------
1 | === Imsanity ===
2 | Contributors: nosilver4u
3 | Donate link: https://ewww.io/donate/
4 | Tags: image, scale, resize, space saver, quality
5 | Tested up to: 6.8
6 | Stable tag: 2.8.7
7 | License: GPLv3
8 |
9 | Automatically resizes huge image uploads. Are contributors uploading huge photos? Tired of manually resizing your images? Imsanity to the rescue!
10 |
11 | == Description ==
12 |
13 | Automatically resize huge image uploads with Imsanity. Choose whatever size and quality you like, and let Imsanity do the rest. When a contributor uploads an image that is larger than the configured size, Imsanity will automatically scale it down to the configured size and replace the original image.
14 |
15 | Imsanity also provides a bulk-resize feature to resize previously uploaded images and free up disk space. You may resize individual images from the Media Library's List View.
16 |
17 | This plugin is ideal for blogs that do not require hi-resolution original images to be stored and/or the contributors don't want (or understand how) to scale images before uploading.
18 |
19 | You may report security issues through our Patchstack Vulnerability Disclosure Program. The Patchstack team helps validate, triage and handle any security vulnerabilities. [Report a security vulnerability.](https://patchstack.com/database/vdp/imsanity)
20 |
21 | = Features =
22 |
23 | * Automatically scales large image uploads to a more "sane" size
24 | * Bulk resize feature to resize existing images
25 | * Selectively resize images directly in the Media Library (List View)
26 | * Allows configuration of max width/height and JPG quality
27 | * Optionally converts BMP and PNG files to JPG for more savings
28 | * Once enabled, Imsanity requires no actions on the part of the user
29 | * Uses WordPress built-in image scaling functions
30 |
31 | = Translations =
32 |
33 | Imsanity is available in several languages, each of which will be downloaded automatically when you install the plugin. To help translate it into your language, visit https://translate.wordpress.org/projects/wp-plugins/imsanity
34 |
35 | = Contribute =
36 |
37 | Imsanity is developed at https://github.com/nosilver4u/imsanity (pull requests are welcome)
38 |
39 | == Installation ==
40 |
41 | Automatic Installation:
42 |
43 | 1. Go to Admin -> Plugins -> Add New and search for "imsanity"
44 | 2. Click the Install Button
45 | 3. Click 'Activate'
46 |
47 | Manual Installation:
48 |
49 | 1. Download imsanity.zip
50 | 2. Unzip and upload the 'imsanity' folder to your '/wp-content/plugins/' directory
51 | 3. Activate the plugin through the 'Plugins' menu in WordPress
52 |
53 | == Screenshots ==
54 |
55 | 1. Imsanity settings page to configure max height/width
56 | 2. Imsanity bulk image resize feature
57 |
58 | == Frequently Asked Questions ==
59 |
60 | = Will installing the Imsanity plugin alter existing images in my blog? =
61 |
62 | Activating Imsanity will not alter any existing images. Imsanity resizes images as they are uploaded so it does not affect existing images unless you specifically use the "Bulk Image Resize" feature on the Imsanity settings page. The Bulk Resize feature allows you to quickly resize existing images.
63 |
64 | = Why am I getting an error saying that my "File is not an image" ? =
65 |
66 | WordPress uses the GD library to handle the image manipulation. GD can be installed and configured to support various types of images. If GD is not configured to handle a particular image type then you will get this message when you try to upload it. For more info see http://php.net/manual/en/image.installation.php
67 |
68 | = How can I tell Imsanity to ignore a certain image so I can upload it without being resized? =
69 |
70 | You can re-name your file and add "-noresize" to the filename. For example if your file is named "photo.jpg" you can rename it "photo-noresize.jpg" and Imsanity will ignore it, allowing you to upload the full-sized image.
71 |
72 | If you are a developer (or have one handy), you can also use the 'imsanity_skip_image' filter to bypass resizing for any image.
73 |
74 | = Does Imsanity compress or optimize my images? =
75 |
76 | While Imsanity does compress JPG images in the process of resizing them, it uses the standard WordPress compression. Thus, the resulting images are not efficiently encoded and can be optimized further (without quality loss) by the EWWW Image Optimizer and many other image optimization plugins.
77 |
78 | = Will Imsanity resize images from plugin X, Y, or Z? =
79 |
80 | If the images can be found in the Media Library of your site, then it is likely Imsanity will resize them. Imsanity uses the wp_handle_upload hook to process new uploads and can resize any existing images in the Media Library using the Bulk Resizer. If the images are not in the Media Library, you can use the EWWW Image Optimizer to resize them.
81 |
82 | = Why would I need this plugin? =
83 |
84 | Photos taken on any modern camera and most cellphones are too large to display full-size in a browser.
85 | This wastes space on your web server, and wastes bandwidth for your visitors to view these files.
86 |
87 | Imsanity allows you to set a sanity limit so that all uploaded images will be constrained to a reasonable size which is still more than large enough for the needs of a typical website. Imsanity hooks into WordPress immediately after the image upload, but before WordPress processing occurs. So WordPress behaves exactly the same in all ways, except it will be as if the contributor had scaled their image to a reasonable size before uploading.
88 |
89 | The size limit that imsanity uses is configurable. The default value is large enough to fill the average vistor's entire screen without scaling so it is still more than large enough for typical usage.
90 |
91 | = Why would I NOT want to use this plugin? =
92 |
93 | You might not want to use Imsanity if you use WordPress as a stock art download site, to provide hi-resolution images for print or use WordPress as a hi-resolution photo storage archive.
94 |
95 | = Doesn't WordPress already automatically scale images? =
96 |
97 | When an image is uploaded WordPress keeps the original and, depending on the size of the original, will create up to 4 smaller sized copies of the file (Large, Medium-Large, Medium, Thumbnail) which are intended for embedding on your pages. Unless you have special photographic needs, the original usually sits there unused, but taking up disk quota.
98 |
99 | = Why did you spell Insanity wrong? =
100 |
101 | Imsanity is short for "Image Sanity Limit". A sanity limit is a term for limiting something down to a size or value that is reasonable.
102 |
103 | = Where do I go for support? =
104 |
105 | Questions may be posted on the support forum at https://wordpress.org/support/plugin/imsanity but if you don't get an answer, please use https://ewww.io/contact-us/.
106 |
107 | == Changelog ==
108 |
109 | = 2.8.7 =
110 | *Release Date = August 6, 2024*
111 |
112 | * added: change default permissions via imsanity_editor_permissions and imsanity_admin_permissions filters
113 | * changed: default permission to resize individual images changed to editor role
114 |
115 | = 2.8.6 =
116 | *Release Date - November 26, 2024*
117 |
118 | * fixed: fatal error if other plugins run big_image_size_threshold filter with too few arguments
119 |
120 | = 2.8.5 =
121 | *Release Date - November 12, 2024*
122 |
123 | * bumped WP tested version
124 | * changed: improve JSON handling/efficiency
125 |
126 | = 2.8.4 =
127 | *Release Date - April 29, 2024*
128 |
129 | * bumped WP tested version and PHP minimum
130 |
131 | = 2.8.3 =
132 | *Release Date - April 23, 2024*
133 |
134 | * changed: use updated WP coding standards
135 | * fixed: PHP 8 error trying to do math with string values
136 |
137 | = 2.8.2 =
138 | *Release Date - October 5, 2022*
139 |
140 | * fixed: mime type error when filename in attachment metadata is incorrect
141 |
142 | = 2.8.1 =
143 | *Release Date - June 16, 2022*
144 |
145 | * changed: escape and sanitize more things
146 | * changed: tighten PHPCS rules used for pre-release testing
147 |
148 | = 2.8.0 =
149 | *Release Date - May 18, 2022*
150 |
151 | * added: support for resizing WebP images via ImageMagick
152 | * changed: update attachment file size to keep WP 6.0 metadata in sync
153 | * changed: use original image for resizing if full size version was scaled by WordPress
154 | * fixed: JS scroller during bulk resize causes unexpected behavior
155 |
156 | = 2.7.2 =
157 | *Release Date - June 3, 2021*
158 |
159 | * fixed: delete originals might remove full-size version in rare cases
160 | * fixed: error thrown for image that is 1 pixel larger than max dimensions
161 |
162 | = 2.7.1 =
163 | *Release Date - November 24, 2020*
164 |
165 | * changed: clarify text for queue reset button
166 | * changed: Delete Originals function in bulk/selective resizer will clean metadata if original image is already gone
167 |
168 | = 2.7.0 =
169 | *Release Date - November 18, 2020*
170 |
171 | * changed: bulk resizer will resize all images with no limits, use list mode for selective resizing
172 | * added: see current dimensions and resize individual images in Media Library list mode
173 | * added: imsanity_disable_convert filter to bypass BMP/PNG to JPG conversion options conditionally
174 | * added: imsanity_skip_image filter to bypass resizing programmatically
175 | * added: ability to remove pre-scaled original image backup (in bulk or selectively)
176 | * changed: PNG images will not be converted if transparency is found
177 | * fixed: BMP files not converted when server uses image/x-ms-bmp as mime identifier
178 | * removed: Deep Scan option is the default behavior now, no need for configuration
179 |
180 | = Earlier versions =
181 | Please refer to the separate changelog.txt file.
182 |
183 | == Credits ==
184 |
185 | Originally written by Jason Hinkle (RIP). Maintained and developed by [Shane Bishop](https://ewww.io) with special thanks to my [Lord and Savior](https://www.iamsecond.com/).
186 |
--------------------------------------------------------------------------------
/imsanity.php:
--------------------------------------------------------------------------------
1 | 0 ) {
117 | imsanity_debug( 'from a post (id)' );
118 | return IMSANITY_SOURCE_POST;
119 | }
120 |
121 | // If the referrer is the post editor, that's a good indication the image is attached to a post.
122 | if ( false !== strpos( $referer, '/post.php' ) ) {
123 | imsanity_debug( 'from a post.php' );
124 | return IMSANITY_SOURCE_POST;
125 | }
126 | // If the referrer is the (new) post editor, that's a good indication the image is attached to a post.
127 | if ( false !== strpos( $referer, '/post-new.php' ) ) {
128 | imsanity_debug( 'from a new post' );
129 | return IMSANITY_SOURCE_POST;
130 | }
131 |
132 | // Post_id of 0 is 3.x otherwise use the action parameter.
133 | if ( 0 === $id || 'upload-attachment' === $action ) {
134 | imsanity_debug( 'from the library' );
135 | return IMSANITY_SOURCE_LIBRARY;
136 | }
137 |
138 | // We don't know where this one came from but $_REQUEST['_wp_http_referer'] may contain info.
139 | imsanity_debug( 'unknown source' );
140 | return IMSANITY_SOURCE_OTHER;
141 | }
142 |
143 | /**
144 | * Given the source, returns the max width/height.
145 | *
146 | * @example: list( $w, $h ) = imsanity_get_max_width_height( IMSANITY_SOURCE_LIBRARY );
147 | * @param int $source One of IMSANITY_SOURCE_POST | IMSANITY_SOURCE_LIBRARY | IMSANITY_SOURCE_OTHER.
148 | */
149 | function imsanity_get_max_width_height( $source ) {
150 | $w = (int) imsanity_get_option( 'imsanity_max_width', IMSANITY_DEFAULT_MAX_WIDTH );
151 | $h = (int) imsanity_get_option( 'imsanity_max_height', IMSANITY_DEFAULT_MAX_HEIGHT );
152 |
153 | switch ( $source ) {
154 | case IMSANITY_SOURCE_POST:
155 | break;
156 | case IMSANITY_SOURCE_LIBRARY:
157 | $w = (int) imsanity_get_option( 'imsanity_max_width_library', $w );
158 | $h = (int) imsanity_get_option( 'imsanity_max_height_library', $h );
159 | break;
160 | default:
161 | $w = (int) imsanity_get_option( 'imsanity_max_width_other', $w );
162 | $h = (int) imsanity_get_option( 'imsanity_max_height_other', $h );
163 | break;
164 | }
165 |
166 | // NOTE: filters MUST return an array of 2 items, or the defaults will be used.
167 | return apply_filters( 'imsanity_get_max_width_height', array( $w, $h ), $source );
168 | }
169 |
170 | /**
171 | * Handler after a file has been uploaded. If the file is an image, check the size
172 | * to see if it is too big and, if so, resize and overwrite the original.
173 | *
174 | * @param Array $params The parameters submitted with the upload.
175 | */
176 | function imsanity_handle_upload( $params ) {
177 |
178 | // If "noresize" is included in the filename then we will bypass imsanity scaling.
179 | if ( strpos( $params['file'], 'noresize' ) !== false ) {
180 | return $params;
181 | }
182 |
183 | if ( apply_filters( 'imsanity_skip_image', false, $params['file'] ) ) {
184 | return $params;
185 | }
186 |
187 | // If preferences specify so then we can convert an original bmp or png file into jpg.
188 | if ( ( 'image/bmp' === $params['type'] || 'image/x-ms-bmp' === $params['type'] ) && imsanity_get_option( 'imsanity_bmp_to_jpg', IMSANITY_DEFAULT_BMP_TO_JPG ) ) {
189 | $params = imsanity_convert_to_jpg( 'bmp', $params );
190 | }
191 |
192 | if ( 'image/png' === $params['type'] && imsanity_get_option( 'imsanity_png_to_jpg', IMSANITY_DEFAULT_PNG_TO_JPG ) ) {
193 | $params = imsanity_convert_to_jpg( 'png', $params );
194 | }
195 |
196 | // Make sure this is a type of image that we want to convert and that it exists.
197 | $oldpath = $params['file'];
198 |
199 | // Let folks filter the allowed mime-types for resizing.
200 | $allowed_types = apply_filters( 'imsanity_allowed_mimes', array( 'image/png', 'image/gif', 'image/jpeg' ), $oldpath );
201 | if ( is_string( $allowed_types ) ) {
202 | $allowed_types = array( $allowed_types );
203 | } elseif ( ! is_array( $allowed_types ) ) {
204 | $allowed_types = array();
205 | }
206 |
207 | if (
208 | ( ! is_wp_error( $params ) ) &&
209 | is_file( $oldpath ) &&
210 | is_readable( $oldpath ) &&
211 | is_writable( $oldpath ) &&
212 | filesize( $oldpath ) > 0 &&
213 | in_array( $params['type'], $allowed_types, true )
214 | ) {
215 |
216 | // figure out where the upload is coming from.
217 | $source = imsanity_get_source();
218 |
219 | $maxw = IMSANITY_DEFAULT_MAX_WIDTH;
220 | $maxh = IMSANITY_DEFAULT_MAX_HEIGHT;
221 | $max_width_height = imsanity_get_max_width_height( $source );
222 | if ( is_array( $max_width_height ) && 2 === count( $max_width_height ) ) {
223 | list( $maxw, $maxh ) = $max_width_height;
224 | }
225 | $maxw = (int) $maxw;
226 | $maxh = (int) $maxh;
227 |
228 | list( $oldw, $oldh ) = getimagesize( $oldpath );
229 |
230 | if ( ( $oldw > $maxw + 1 && $maxw > 0 ) || ( $oldh > $maxh + 1 && $maxh > 0 ) ) {
231 | $quality = imsanity_get_option( 'imsanity_quality', IMSANITY_DEFAULT_QUALITY );
232 |
233 | $ftype = imsanity_quick_mimetype( $oldpath );
234 | $orientation = imsanity_get_orientation( $oldpath, $ftype );
235 | // If we are going to rotate the image 90 degrees during the resize, swap the existing image dimensions.
236 | if ( 6 === (int) $orientation || 8 === (int) $orientation ) {
237 | $old_oldw = $oldw;
238 | $oldw = $oldh;
239 | $oldh = $old_oldw;
240 | }
241 |
242 | if ( $maxw > 0 && $maxh > 0 && $oldw >= $maxw && $oldh >= $maxh && ( $oldh > $maxh || $oldw > $maxw ) && apply_filters( 'imsanity_crop_image', false ) ) {
243 | $neww = $maxw;
244 | $newh = $maxh;
245 | } else {
246 | list( $neww, $newh ) = wp_constrain_dimensions( $oldw, $oldh, $maxw, $maxh );
247 | }
248 |
249 | global $ewww_preempt_editor;
250 | if ( ! isset( $ewww_preempt_editor ) ) {
251 | $ewww_preempt_editor = false;
252 | }
253 | $original_preempt = $ewww_preempt_editor;
254 | $ewww_preempt_editor = true;
255 | $resizeresult = imsanity_image_resize( $oldpath, $neww, $newh, apply_filters( 'imsanity_crop_image', false ), null, null, $quality );
256 | $ewww_preempt_editor = $original_preempt;
257 |
258 | if ( $resizeresult && ! is_wp_error( $resizeresult ) ) {
259 | $newpath = $resizeresult;
260 |
261 | if ( is_file( $newpath ) && filesize( $newpath ) < filesize( $oldpath ) ) {
262 | // We saved some file space. remove original and replace with resized image.
263 | unlink( $oldpath );
264 | rename( $newpath, $oldpath );
265 | } elseif ( is_file( $newpath ) ) {
266 | // The resized image is actually bigger in filesize (most likely due to jpg quality).
267 | // Keep the old one and just get rid of the resized image.
268 | unlink( $newpath );
269 | }
270 | } elseif ( false === $resizeresult ) {
271 | return $params;
272 | } elseif ( is_wp_error( $resizeresult ) ) {
273 | // resize didn't work, likely because the image processing libraries are missing.
274 | // remove the old image so we don't leave orphan files hanging around.
275 | unlink( $oldpath );
276 |
277 | $params = wp_handle_upload_error(
278 | $oldpath,
279 | sprintf(
280 | /* translators: 1: error message 2: link to support forums */
281 | esc_html__( 'Imsanity was unable to resize this image for the following reason: %1$s. If you continue to see this error message, you may need to install missing server components. If you think you have discovered a bug, please report it on the Imsanity support forum: %2$s', 'imsanity' ),
282 | $resizeresult->get_error_message(),
283 | 'https://wordpress.org/support/plugin/imsanity'
284 | )
285 | );
286 | } else {
287 | return $params;
288 | }
289 | }
290 | }
291 | clearstatcache();
292 | return $params;
293 | }
294 |
295 |
296 | /**
297 | * Read in the image file from the params and then save as a new jpg file.
298 | * if successful, remove the original image and alter the return
299 | * parameters to return the new jpg instead of the original
300 | *
301 | * @param string $type Type of the image to be converted: 'bmp' or 'png'.
302 | * @param array $params The upload parameters.
303 | * @return array altered params
304 | */
305 | function imsanity_convert_to_jpg( $type, $params ) {
306 |
307 | if ( apply_filters( 'imsanity_disable_convert', false, $type, $params ) ) {
308 | return $params;
309 | }
310 |
311 | $img = null;
312 |
313 | if ( 'bmp' === $type ) {
314 | if ( ! function_exists( 'imagecreatefrombmp' ) ) {
315 | return $params;
316 | }
317 | $img = imagecreatefrombmp( $params['file'] );
318 | } elseif ( 'png' === $type ) {
319 | // Prevent converting PNG images with alpha/transparency, unless overridden by the user.
320 | if ( apply_filters( 'imsanity_skip_alpha', imsanity_has_alpha( $params['file'] ), $params['file'] ) ) {
321 | return $params;
322 | }
323 | if ( ! function_exists( 'imagecreatefrompng' ) ) {
324 | return wp_handle_upload_error( $params['file'], esc_html__( 'Imsanity requires the GD library to convert PNG images to JPG', 'imsanity' ) );
325 | }
326 |
327 | $input = imagecreatefrompng( $params['file'] );
328 | // convert png transparency to white.
329 | $img = imagecreatetruecolor( imagesx( $input ), imagesy( $input ) );
330 | imagefill( $img, 0, 0, imagecolorallocate( $img, 255, 255, 255 ) );
331 | imagealphablending( $img, true );
332 | imagecopy( $img, $input, 0, 0, 0, 0, imagesx( $input ), imagesy( $input ) );
333 | } else {
334 | return wp_handle_upload_error( $params['file'], esc_html__( 'Unknown image type specified in imsanity_convert_to_jpg', 'imsanity' ) );
335 | }
336 |
337 | // We need to change the extension from the original to .jpg so we have to ensure it will be a unique filename.
338 | $uploads = wp_upload_dir();
339 | $oldfilename = wp_basename( $params['file'] );
340 | $newfilename = wp_basename( str_ireplace( '.' . $type, '.jpg', $oldfilename ) );
341 | $newfilename = wp_unique_filename( $uploads['path'], $newfilename );
342 |
343 | $quality = imsanity_get_option( 'imsanity_quality', IMSANITY_DEFAULT_QUALITY );
344 |
345 | if ( imagejpeg( $img, $uploads['path'] . '/' . $newfilename, $quality ) ) {
346 | // Conversion succeeded: remove the original bmp & remap the params.
347 | unlink( $params['file'] );
348 |
349 | $params['file'] = $uploads['path'] . '/' . $newfilename;
350 | $params['url'] = $uploads['url'] . '/' . $newfilename;
351 | $params['type'] = 'image/jpeg';
352 | } else {
353 | unlink( $params['file'] );
354 |
355 | return wp_handle_upload_error(
356 | $oldfilename,
357 | /* translators: %s: the image mime type */
358 | sprintf( esc_html__( 'Imsanity was unable to process the %s file. If you continue to see this error you may need to disable the conversion option in the Imsanity settings.', 'imsanity' ), $type )
359 | );
360 | }
361 |
362 | return $params;
363 | }
364 |
365 | // Add filter to hook into uploads.
366 | add_filter( 'wp_handle_upload', 'imsanity_handle_upload' );
367 | // Run necessary actions on init (loading translations mostly).
368 | add_action( 'plugins_loaded', 'imsanity_init' );
369 |
370 | // Adds a column to the media library list view to display optimization results.
371 | add_filter( 'manage_media_columns', 'imsanity_media_columns' );
372 | // Outputs the actual column information for each attachment.
373 | add_action( 'manage_media_custom_column', 'imsanity_custom_column', 10, 2 );
374 | // Checks for WebP support and adds it to the allowed mime types.
375 | add_filter( 'imsanity_allowed_mimes', 'imsanity_add_webp_support' );
376 |
--------------------------------------------------------------------------------
/libs/utils.php:
--------------------------------------------------------------------------------
1 | queryFormats();
90 | if ( in_array( 'WEBP', $formats, true ) ) {
91 | $mimes[] = 'image/webp';
92 | }
93 | }
94 | }
95 | return $mimes;
96 | }
97 |
98 | /**
99 | * Gets the orientation/rotation of a JPG image using the EXIF data.
100 | *
101 | * @param string $file Name of the file.
102 | * @param string $type Mime type of the file.
103 | * @return int|bool The orientation value or false.
104 | */
105 | function imsanity_get_orientation( $file, $type ) {
106 | if ( function_exists( 'exif_read_data' ) && 'image/jpeg' === $type ) {
107 | $exif = @exif_read_data( $file ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
108 | if ( is_array( $exif ) && array_key_exists( 'Orientation', $exif ) ) {
109 | return (int) $exif['Orientation'];
110 | }
111 | }
112 | return false;
113 | }
114 |
115 | /**
116 | * Check an image to see if it has transparency.
117 | *
118 | * @param string $filename The name of the image file.
119 | * @return bool True if transparency is found.
120 | */
121 | function imsanity_has_alpha( $filename ) {
122 | if ( ! is_file( $filename ) ) {
123 | return false;
124 | }
125 | if ( false !== strpos( $filename, '../' ) ) {
126 | return false;
127 | }
128 | $file_contents = file_get_contents( $filename );
129 | // Determine what color type is stored in the file.
130 | $color_type = ord( substr( $file_contents, 25, 1 ) );
131 | // If we do not have GD and the PNG color type is RGB alpha or Grayscale alpha.
132 | if ( ! imsanity_gd_support() && ( 4 === $color_type || 6 === $color_type ) ) {
133 | return true;
134 | } elseif ( imsanity_gd_support() ) {
135 | $image = imagecreatefrompng( $filename );
136 | if ( imagecolortransparent( $image ) >= 0 ) {
137 | return true;
138 | }
139 | list( $width, $height ) = getimagesize( $filename );
140 | for ( $y = 0; $y < $height; $y++ ) {
141 | for ( $x = 0; $x < $width; $x++ ) {
142 | $color = imagecolorat( $image, $x, $y );
143 | $rgb = imagecolorsforindex( $image, $color );
144 | if ( $rgb['alpha'] > 0 ) {
145 | return true;
146 | }
147 | }
148 | }
149 | }
150 | return false;
151 | }
152 |
153 | /**
154 | * Check for GD support of both PNG and JPG.
155 | *
156 | * @return bool True if full GD support is detected.
157 | */
158 | function imsanity_gd_support() {
159 | if ( function_exists( 'gd_info' ) ) {
160 | $gd_support = gd_info();
161 | if ( is_iterable( $gd_support ) ) {
162 | if ( ( ! empty( $gd_support['JPEG Support'] ) || ! empty( $gd_support['JPG Support'] ) ) && ! empty( $gd_support['PNG Support'] ) ) {
163 | return true;
164 | }
165 | }
166 | }
167 | return false;
168 | }
169 |
170 | /**
171 | * Resizes the image with the given id according to the configured max width and height settings.
172 | *
173 | * @param int $id The attachment ID of the image to process.
174 | * @return array The success status (bool) and a message to display.
175 | */
176 | function imsanity_resize_from_id( $id = 0 ) {
177 |
178 | $id = (int) $id;
179 |
180 | if ( ! $id ) {
181 | return;
182 | }
183 |
184 | $meta = wp_get_attachment_metadata( $id );
185 |
186 | if ( $meta && is_array( $meta ) ) {
187 | $update_meta = false;
188 | // If "noresize" is included in the filename then we will bypass imsanity scaling.
189 | if ( ! empty( $meta['file'] ) && false !== strpos( $meta['file'], 'noresize' ) ) {
190 | /* translators: %s: File-name of the image */
191 | $msg = sprintf( esc_html__( 'SKIPPED: %s (noresize)', 'imsanity' ), $meta['file'] );
192 | return array(
193 | 'success' => false,
194 | 'message' => $msg,
195 | );
196 | }
197 |
198 | // $uploads = wp_upload_dir();
199 | $oldpath = imsanity_attachment_path( $meta, $id, '', false );
200 |
201 | if ( empty( $oldpath ) ) {
202 | /* translators: %s: File-name of the image */
203 | $msg = sprintf( esc_html__( 'Could not retrieve location of %s', 'imsanity' ), $meta['file'] );
204 | return array(
205 | 'success' => false,
206 | 'message' => $msg,
207 | );
208 | }
209 |
210 | // Let folks filter the allowed mime-types for resizing.
211 | $allowed_types = apply_filters( 'imsanity_allowed_mimes', array( 'image/png', 'image/gif', 'image/jpeg' ), $oldpath );
212 | if ( is_string( $allowed_types ) ) {
213 | $allowed_types = array( $allowed_types );
214 | } elseif ( ! is_array( $allowed_types ) ) {
215 | $allowed_types = array();
216 | }
217 | $ftype = imsanity_quick_mimetype( $oldpath );
218 | if ( ! in_array( $ftype, $allowed_types, true ) ) {
219 | /* translators: %s: File type of the image */
220 | $msg = sprintf( esc_html__( '%1$s does not have an allowed file type (%2$s)', 'imsanity' ), wp_basename( $oldpath ), $ftype );
221 | return array(
222 | 'success' => false,
223 | 'message' => $msg,
224 | );
225 | }
226 |
227 | if ( ! is_writable( $oldpath ) ) {
228 | /* translators: %s: File-name of the image */
229 | $msg = sprintf( esc_html__( '%s is not writable', 'imsanity' ), $meta['file'] );
230 | return array(
231 | 'success' => false,
232 | 'message' => $msg,
233 | );
234 | }
235 |
236 | if ( apply_filters( 'imsanity_skip_image', false, $oldpath ) ) {
237 | /* translators: %s: File-name of the image */
238 | $msg = sprintf( esc_html__( 'SKIPPED: %s (by user exclusion)', 'imsanity' ), $meta['file'] );
239 | return array(
240 | 'success' => false,
241 | 'message' => $msg,
242 | );
243 | }
244 |
245 | $maxw = imsanity_get_option( 'imsanity_max_width', IMSANITY_DEFAULT_MAX_WIDTH );
246 | $maxh = imsanity_get_option( 'imsanity_max_height', IMSANITY_DEFAULT_MAX_HEIGHT );
247 |
248 | // method one - slow but accurate, get file size from file itself.
249 | list( $oldw, $oldh ) = getimagesize( $oldpath );
250 | // method two - get file size from meta, fast but resize will fail if meta is out of sync.
251 | if ( ! $oldw || ! $oldh ) {
252 | $oldw = $meta['width'];
253 | $oldh = $meta['height'];
254 | }
255 |
256 | if ( ( $oldw > $maxw && $maxw > 0 ) || ( $oldh > $maxh && $maxh > 0 ) ) {
257 | $quality = imsanity_get_option( 'imsanity_quality', IMSANITY_DEFAULT_QUALITY );
258 |
259 | if ( $maxw > 0 && $maxh > 0 && $oldw >= $maxw && $oldh >= $maxh && ( $oldh > $maxh || $oldw > $maxw ) && apply_filters( 'imsanity_crop_image', false ) ) {
260 | $neww = $maxw;
261 | $newh = $maxh;
262 | } else {
263 | list( $neww, $newh ) = wp_constrain_dimensions( $oldw, $oldh, $maxw, $maxh );
264 | }
265 |
266 | $source_image = $oldpath;
267 | if ( ! empty( $meta['original_image'] ) ) {
268 | $source_image = path_join( dirname( $oldpath ), $meta['original_image'] );
269 | imsanity_debug( "subbing in $source_image for resizing" );
270 | }
271 | $resizeresult = imsanity_image_resize( $source_image, $neww, $newh, apply_filters( 'imsanity_crop_image', false ), null, null, $quality );
272 |
273 | if ( $resizeresult && ! is_wp_error( $resizeresult ) ) {
274 | $newpath = $resizeresult;
275 |
276 | if ( $newpath !== $oldpath && is_file( $newpath ) && filesize( $newpath ) < filesize( $oldpath ) ) {
277 | // we saved some file space. remove original and replace with resized image.
278 | unlink( $oldpath );
279 | rename( $newpath, $oldpath );
280 | $meta['width'] = $neww;
281 | $meta['height'] = $newh;
282 |
283 | $update_meta = true;
284 |
285 | $results = array(
286 | 'success' => true,
287 | 'id' => $id,
288 | /* translators: 1: File-name of the image */
289 | 'message' => sprintf( esc_html__( 'OK: %1$s resized to %2$s x %3$s', 'imsanity' ), $meta['file'], $neww . 'w', $newh . 'h' ),
290 | );
291 | } elseif ( $newpath !== $oldpath ) {
292 | // the resized image is actually bigger in filesize (most likely due to jpg quality).
293 | // keep the old one and just get rid of the resized image.
294 | if ( is_file( $newpath ) ) {
295 | unlink( $newpath );
296 | }
297 | $results = array(
298 | 'success' => false,
299 | 'id' => $id,
300 | /* translators: 1: File-name of the image 2: the error message, translated elsewhere */
301 | 'message' => sprintf( esc_html__( 'ERROR: %1$s (%2$s)', 'imsanity' ), $meta['file'], esc_html__( 'File size of resized image was larger than the original', 'imsanity' ) ),
302 | );
303 | } else {
304 | $results = array(
305 | 'success' => false,
306 | 'id' => $id,
307 | /* translators: 1: File-name of the image 2: the error message, translated elsewhere */
308 | 'message' => sprintf( esc_html__( 'ERROR: %1$s (%2$s)', 'imsanity' ), $meta['file'], esc_html__( 'Unknown error, resizing function returned the same filename', 'imsanity' ) ),
309 | );
310 | }
311 | } elseif ( false === $resizeresult ) {
312 | $results = array(
313 | 'success' => false,
314 | 'id' => $id,
315 | /* translators: 1: File-name of the image 2: the error message, translated elsewhere */
316 | 'message' => sprintf( esc_html__( 'ERROR: %1$s (%2$s)', 'imsanity' ), $meta['file'], esc_html__( 'wp_get_image_editor missing', 'imsanity' ) ),
317 | );
318 | } else {
319 | $results = array(
320 | 'success' => false,
321 | 'id' => $id,
322 | /* translators: 1: File-name of the image 2: the error message, translated elsewhere */
323 | 'message' => sprintf( esc_html__( 'ERROR: %1$s (%2$s)', 'imsanity' ), $meta['file'], htmlentities( $resizeresult->get_error_message() ) ),
324 | );
325 | }
326 | } else {
327 | $results = array(
328 | 'success' => true,
329 | 'id' => $id,
330 | /* translators: %s: File-name of the image */
331 | 'message' => sprintf( esc_html__( 'SKIPPED: %s (Resize not required)', 'imsanity' ), $meta['file'] ) . " -- $oldw x $oldh",
332 | );
333 | if ( empty( $meta['width'] ) || empty( $meta['height'] ) ) {
334 | if ( empty( $meta['width'] ) || $meta['width'] > $oldw ) {
335 | $meta['width'] = $oldw;
336 | }
337 | if ( empty( $meta['height'] ) || $meta['height'] > $oldh ) {
338 | $meta['height'] = $oldh;
339 | }
340 | $update_meta = true;
341 | }
342 | }
343 | $remove_original = imsanity_remove_original_image( $id, $meta );
344 | if ( $remove_original && is_array( $remove_original ) ) {
345 | $meta = $remove_original;
346 | $update_meta = true;
347 | }
348 | if ( ! empty( $update_meta ) ) {
349 | clearstatcache();
350 | if ( ! empty( $oldpath ) && is_file( $oldpath ) ) {
351 | $meta['filesize'] = filesize( $oldpath );
352 | }
353 | wp_update_attachment_metadata( $id, $meta );
354 | do_action( 'imsanity_post_process_attachment', $id, $meta );
355 | }
356 | } else {
357 | $results = array(
358 | 'success' => false,
359 | 'id' => $id,
360 | /* translators: %s: ID number of the image */
361 | 'message' => sprintf( esc_html__( 'ERROR: Attachment with ID of %d not found', 'imsanity' ), intval( $id ) ),
362 | );
363 | }
364 |
365 | // If there is a quota we need to reset the directory size cache so it will re-calculate.
366 | delete_transient( 'dirsize_cache' );
367 |
368 | return $results;
369 | }
370 |
371 | /**
372 | * Find the path to a backed-up original (not the full-size version like the core WP function).
373 | *
374 | * @param int $id The attachment ID number.
375 | * @param string $image_file The path to a scaled image file.
376 | * @param array $meta The attachment metadata. Optional, default to null.
377 | * @return bool True on success, false on failure.
378 | */
379 | function imsanity_get_original_image_path( $id, $image_file = '', $meta = null ) {
380 | $id = (int) $id;
381 | if ( empty( $id ) ) {
382 | return false;
383 | }
384 | if ( ! wp_attachment_is_image( $id ) ) {
385 | return false;
386 | }
387 | if ( is_null( $meta ) ) {
388 | $meta = wp_get_attachment_metadata( $id );
389 | }
390 | if ( empty( $image_file ) ) {
391 | $image_file = get_attached_file( $id, true );
392 | }
393 | if ( empty( $image_file ) || ! is_iterable( $meta ) || empty( $meta['original_image'] ) ) {
394 | return false;
395 | }
396 |
397 | return trailingslashit( dirname( $image_file ) ) . wp_basename( $meta['original_image'] );
398 | }
399 |
400 | /**
401 | * Remove the backed-up original_image stored by WP 5.3+.
402 | *
403 | * @param int $id The attachment ID number.
404 | * @param array $meta The attachment metadata. Optional, default to null.
405 | * @return bool|array Returns meta if modified, false otherwise (even if an "unlinked" original is removed).
406 | */
407 | function imsanity_remove_original_image( $id, $meta = null ) {
408 | $id = (int) $id;
409 | if ( empty( $id ) ) {
410 | return false;
411 | }
412 | if ( is_null( $meta ) ) {
413 | $meta = wp_get_attachment_metadata( $id );
414 | }
415 |
416 | if (
417 | $meta && is_array( $meta ) &&
418 | imsanity_get_option( 'imsanity_delete_originals', false ) &&
419 | ! empty( $meta['original_image'] ) && function_exists( 'wp_get_original_image_path' )
420 | ) {
421 | $original_image = imsanity_get_original_image_path( $id, '', $meta );
422 | if ( $original_image && is_file( $original_image ) && is_writable( $original_image ) ) {
423 | unlink( $original_image );
424 | }
425 | clearstatcache();
426 | if ( empty( $original_image ) || ! is_file( $original_image ) ) {
427 | unset( $meta['original_image'] );
428 | return $meta;
429 | }
430 | }
431 | return false;
432 | }
433 |
434 | /**
435 | * Resize an image using the WP_Image_Editor.
436 | *
437 | * @param string $file Image file path.
438 | * @param int $max_w Maximum width to resize to.
439 | * @param int $max_h Maximum height to resize to.
440 | * @param bool $crop Optional. Whether to crop image or resize.
441 | * @param string $suffix Optional. File suffix.
442 | * @param string $dest_path Optional. New image file path.
443 | * @param int $jpeg_quality Optional, default is 82. Image quality level (1-100).
444 | * @return mixed WP_Error on failure. String with new destination path.
445 | */
446 | function imsanity_image_resize( $file, $max_w, $max_h, $crop = false, $suffix = null, $dest_path = null, $jpeg_quality = 82 ) {
447 | if ( function_exists( 'wp_get_image_editor' ) ) {
448 | imsanity_debug( "resizing $file" );
449 | $editor = wp_get_image_editor( $file );
450 | if ( is_wp_error( $editor ) ) {
451 | return $editor;
452 | }
453 |
454 | $ftype = imsanity_quick_mimetype( $file );
455 | if ( 'image/webp' === $ftype ) {
456 | $jpeg_quality = (int) round( $jpeg_quality * .91 );
457 | }
458 |
459 | $editor->set_quality( min( 92, $jpeg_quality ) );
460 |
461 | // Return 1 to override auto-rotate.
462 | $orientation = (int) apply_filters( 'imsanity_orientation', imsanity_get_orientation( $file, $ftype ) );
463 | // Try to correct for auto-rotation if the info is available.
464 | switch ( $orientation ) {
465 | case 3:
466 | $editor->rotate( 180 );
467 | break;
468 | case 6:
469 | $editor->rotate( -90 );
470 | break;
471 | case 8:
472 | $editor->rotate( 90 );
473 | break;
474 | }
475 |
476 | $resized = $editor->resize( $max_w, $max_h, $crop );
477 | if ( is_wp_error( $resized ) ) {
478 | return $resized;
479 | }
480 |
481 | $dest_file = $editor->generate_filename( $suffix, $dest_path );
482 |
483 | // Make sure that the destination file does not exist.
484 | if ( file_exists( $dest_file ) ) {
485 | $dest_file = $editor->generate_filename( 'TMP', $dest_path );
486 | }
487 |
488 | $saved = $editor->save( $dest_file );
489 |
490 | if ( is_wp_error( $saved ) ) {
491 | return $saved;
492 | }
493 |
494 | return $dest_file;
495 | }
496 | return false;
497 | }
498 |
--------------------------------------------------------------------------------
/settings.php:
--------------------------------------------------------------------------------
1 | imsanity_ms ) ) {
11 | $wpdb->imsanity_ms = $wpdb->get_blog_prefix( 0 ) . 'imsanity';
12 | }
13 |
14 | // Register the plugin settings menu.
15 | add_action( 'admin_menu', 'imsanity_create_menu' );
16 | add_action( 'network_admin_menu', 'imsanity_register_network' );
17 | add_filter( 'plugin_action_links_' . IMSANITY_PLUGIN_FILE_REL, 'imsanity_settings_link' );
18 | add_filter( 'network_admin_plugin_action_links_' . IMSANITY_PLUGIN_FILE_REL, 'imsanity_settings_link' );
19 | add_action( 'admin_enqueue_scripts', 'imsanity_queue_script' );
20 | add_action( 'admin_init', 'imsanity_register_settings' );
21 | add_filter( 'big_image_size_threshold', 'imsanity_adjust_default_threshold', 10, 3 );
22 |
23 | register_activation_hook( IMSANITY_PLUGIN_FILE_REL, 'imsanity_maybe_created_custom_table' );
24 |
25 | // settings cache.
26 | $_imsanity_multisite_settings = null;
27 |
28 | /**
29 | * Create the settings menu item in the WordPress admin navigation and
30 | * link it to the plugin settings page
31 | */
32 | function imsanity_create_menu() {
33 | $permissions = apply_filters( 'imsanity_admin_permissions', 'manage_options' );
34 | // Create new menu for site configuration.
35 | add_options_page(
36 | esc_html__( 'Imsanity Plugin Settings', 'imsanity' ), // Page Title.
37 | esc_html__( 'Imsanity', 'imsanity' ), // Menu Title.
38 | $permissions, // Required permissions.
39 | IMSANITY_PLUGIN_FILE_REL, // Slug.
40 | 'imsanity_settings_page' // Function to call.
41 | );
42 | }
43 |
44 | /**
45 | * Register the network settings page
46 | */
47 | function imsanity_register_network() {
48 | if ( ! function_exists( 'is_plugin_active_for_network' ) && is_multisite() ) {
49 | // Need to include the plugin library for the is_plugin_active function.
50 | require_once ABSPATH . 'wp-admin/includes/plugin.php';
51 | }
52 | if ( is_multisite() ) {
53 | $permissions = apply_filters( 'imsanity_superadmin_permissions', 'manage_network_options' );
54 | add_submenu_page(
55 | 'settings.php',
56 | esc_html__( 'Imsanity Network Settings', 'imsanity' ),
57 | esc_html__( 'Imsanity', 'imsanity' ),
58 | $permissions,
59 | IMSANITY_PLUGIN_FILE_REL,
60 | 'imsanity_network_settings'
61 | );
62 | }
63 | }
64 |
65 | /**
66 | * Settings link that appears on the plugins overview page
67 | *
68 | * @param array $links The plugin action links.
69 | * @return array The action links, with a settings link pre-pended.
70 | */
71 | function imsanity_settings_link( $links ) {
72 | if ( ! is_array( $links ) ) {
73 | $links = array();
74 | }
75 | if ( is_multisite() && is_network_admin() ) {
76 | $settings_link = '' . esc_html__( 'Settings', 'imsanity' ) . '';
77 | } else {
78 | $settings_link = '' . esc_html__( 'Settings', 'imsanity' ) . '';
79 | }
80 | array_unshift( $links, $settings_link );
81 | return $links;
82 | }
83 |
84 | /**
85 | * Queues up the AJAX script and any localized JS vars we need.
86 | *
87 | * @param string $hook The hook name for the current page.
88 | */
89 | function imsanity_queue_script( $hook ) {
90 | // Make sure we are being called from the settings page.
91 | if ( strpos( $hook, 'settings_page_imsanity' ) !== 0 && 'upload.php' !== $hook ) {
92 | return;
93 | }
94 | if ( ! empty( $_REQUEST['imsanity_reset'] ) && ! empty( $_REQUEST['imsanity_wpnonce'] ) && wp_verify_nonce( sanitize_key( $_REQUEST['imsanity_wpnonce'] ), 'imsanity-bulk-reset' ) ) {
95 | update_option( 'imsanity_resume_id', 0, false );
96 | }
97 | $resume_id = (int) get_option( 'imsanity_resume_id' );
98 | $loading_image = plugins_url( '/images/ajax-loader.gif', __FILE__ );
99 | // Register the scripts that are used by the bulk resizer.
100 | wp_enqueue_script( 'imsanity_script', plugins_url( '/scripts/imsanity.js', __FILE__ ), array( 'jquery' ), IMSANITY_VERSION );
101 | wp_localize_script(
102 | 'imsanity_script',
103 | 'imsanity_vars',
104 | array(
105 | '_wpnonce' => wp_create_nonce( 'imsanity-bulk' ),
106 | 'resize_all_prompt' => esc_html__( 'You are about to resize all your existing images. Please be sure your site is backed up before proceeding. Do you wish to continue?', 'imsanity' ),
107 | 'resizing_complete' => esc_html__( 'Resizing Complete', 'imsanity' ) . ' - ' . esc_html__( 'Leave a Review', 'imsanity' ) . '',
108 | 'resize_selected' => esc_html__( 'Resize Selected Images', 'imsanity' ),
109 | 'resizing' => '
" . esc_html__( 'The GD extension is not enabled in PHP, Imsanity may not function correctly. Enable GD or contact your web host for assistance.', 'imsanity' ) . '