=== Smart Gallery Optimizer ===
Contributors: sabiburrahman
Tags: gallery, image optimization, webp, avif, lazy loading, responsive, lightbox, seo, exif, performance
Requires at least: 5.0
Tested up to: 6.4
Requires PHP: 8.0
Stable tag: 1.0.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Enhance gallery performance with automatic WebP/AVIF conversion, lazy loading, responsive layouts, PhotoSwipe lightbox, and EXIF-based alt-text generation.

== Description ==

Smart Gallery Optimizer is a comprehensive WordPress plugin that combines image optimization, responsive galleries, and SEO features into one powerful tool. Reduce image file sizes by 30-50%, improve page load speeds, and boost SEO with automatic alt-text generation.

= Key Features =

**Image Optimization**

* Automatic WebP conversion on upload (25-35% smaller files)
* AVIF support for superior compression (30-50% smaller files)
* Quality control for WebP and AVIF (1-100)
* Original image preservation for browser fallback
* Server capability detection

**Performance & Display**

* Lazy loading with Intersection Observer API
* Responsive CSS Grid layouts (2-6 columns)
* Mobile-optimized (automatic single column on mobile)
* Conditional asset loading (only when needed)
* Minified CSS and JavaScript files

**Gallery Management**

* Visual gallery manager with drag-and-drop
* Save, edit, delete, and duplicate galleries
* WordPress Media Library integration
* Per-gallery settings (columns, size, gap, link behavior)
* One-click shortcode copy to clipboard

**PhotoSwipe Lightbox**

* Modern touch-friendly lightbox
* Pinch-to-zoom support (mobile)
* Swipe navigation (mobile)
* Keyboard navigation (desktop)
* Optional image titles and captions
* Full-screen viewing

**EXIF & SEO Features**

* Automatic EXIF metadata extraction
* Auto-generate SEO-friendly alt-text
* Customizable alt-text templates
* Camera, date, and location data support
* Bulk alt-text generator (process 100+ images)
* Filename-based fallback

**Developer Friendly**

* Action hooks and filter hooks
* Well-documented code
* Theme compatible
* Page builder support (Gutenberg, Elementor, Divi, WPBakery)
* Extensible architecture

= How It Works =

**Image Optimization:**
1. Upload images through WordPress Media Library
2. Plugin automatically creates WebP and AVIF versions
3. Original images preserved as fallback
4. Modern browsers receive optimized formats
5. Older browsers receive original images

**Smart Galleries:**
1. Create gallery using Gallery Manager or shortcode
2. Images load lazily as user scrolls
3. Responsive grid adapts to screen size
4. PhotoSwipe lightbox for viewing (optional)
5. SEO-optimized with auto-generated alt-text

= Shortcode Usage =

**Saved Gallery:**
`[smart_gallery id="123"]`

**Legacy Format:**
`[smart_gallery ids="1,2,3,4,5,6" columns="3" size="medium" gap="20"]`

**Attributes:**
* `id` - Saved gallery ID (from Gallery Manager)
* `ids` - Comma-separated image attachment IDs
* `columns` - Number of columns: 2-6 (default: 3)
* `size` - Image size: thumbnail, medium, large, full (default: medium)
* `gap` - Gap spacing in pixels: 0-100 (default: 20)

= Performance Benefits =

* **WebP:** 25-35% smaller than JPEG
* **AVIF:** 30-50% smaller than JPEG
* **Lazy Loading:** 40-60% faster initial page load
* **Combined:** 60-80% overall performance improvement

= Browser Support =

**WebP:**
* Chrome 23+
* Firefox 65+
* Safari 14+
* Edge 18+

**AVIF:**
* Chrome 85+
* Firefox 93+
* Safari 16+
* Edge 121+

**Lazy Loading (Intersection Observer):**
* All modern browsers (95%+ global support)
* Automatic fallback for older browsers

= Use Cases =

* Photography portfolios
* E-commerce product galleries
* Blog image galleries
* Real estate listings
* Travel photography sites
* Art galleries
* Event photography
* Before/after comparisons

== Installation ==

= Automatic Installation =

1. Log in to your WordPress admin panel
2. Navigate to **Plugins > Add New**
3. Search for "Smart Gallery Optimizer"
4. Click **Install Now**
5. Click **Activate**
6. Go to **Smart Gallery** to configure settings

= Manual Installation =

1. Download the plugin ZIP file
2. Log in to your WordPress admin panel
3. Navigate to **Plugins > Add New > Upload Plugin**
4. Click **Choose File** and select the downloaded ZIP
5. Click **Install Now**
6. Click **Activate Plugin**
7. Go to **Smart Gallery** to configure settings

= FTP Installation =

1. Download and extract the plugin ZIP file
2. Upload the `smart-gallery-optimizer` folder to `/wp-content/plugins/` via FTP
3. Log in to WordPress admin panel
4. Navigate to **Plugins > Installed Plugins**
5. Find "Smart Gallery Optimizer" and click **Activate**
6. Go to **Smart Gallery** to configure settings

= Initial Setup =

1. Navigate to **Smart Gallery** in admin sidebar
2. Configure **Conversion Settings** (WebP/AVIF quality)
3. Configure **Performance & Display** (lazy loading, columns)
4. Configure **EXIF & SEO** (auto alt-text settings)
5. Configure **Link Behavior** (lightbox options)
6. Click **Save Changes**

= First Gallery =

**Method 1: Gallery Manager (Recommended)**
1. Go to **Smart Gallery > Gallery List**
2. Click **Create New Gallery**
3. Enter gallery name
4. Click **Add Images** and select from media library
5. Configure settings (columns, size, gap, link type)
6. Click **Save Gallery**
7. Copy shortcode and paste into page/post

**Method 2: Shortcode**
1. Find image IDs in **Media > Library**
2. Add shortcode to page: `[smart_gallery ids="1,2,3,4,5,6"]`
3. Customize with attributes (columns, size, gap)

== Frequently Asked Questions ==

= Will this work with my theme? =

Yes! Smart Gallery Optimizer works with all standard WordPress themes and popular page builders including Gutenberg, Elementor, WPBakery, and Divi.

= Do I need to convert existing images? =

Images uploaded before activation are not automatically converted. Only new uploads are converted. You can use the Bulk Alt-Text Generator for existing images, but bulk conversion may be added in a future update.

= What happens to my original images? =

Original images are always preserved. WebP and AVIF versions are created alongside originals for browser fallback. If you uninstall the plugin, you can optionally delete the converted versions.

= Can I disable WebP/AVIF conversion? =

Yes. Go to **Smart Gallery > Conversion Settings** and toggle WebP/AVIF conversion OFF. Existing converted files will remain but new uploads won't be converted.

= Why isn't AVIF working? =

AVIF requires PHP 8.1+ with GD library and AVIF support. Check **Smart Gallery > Conversion Settings** to see if your server supports AVIF. Contact your hosting provider if needed.

= How do I find image attachment IDs? =

Go to **Media > Library**, click an image, and look at the browser URL. The ID is the number in `post.php?post=123&action=edit` (123 is the ID).

= Can I use multiple galleries on one page? =

Yes! You can use multiple `[smart_gallery]` shortcodes on the same page. Each gallery is independent with its own settings.

= Does lazy loading work without JavaScript? =

If JavaScript is disabled or the browser doesn't support Intersection Observer, images load immediately as fallback.

= Can I disable the smart grid? =

Yes. Go to **Smart Gallery > Performance & Display Settings** and toggle "Enable Smart Grid" OFF. It will fall back to WordPress default gallery.

= Will auto alt-text override existing alt-text? =

No! The plugin only generates alt-text for images that don't have it. Existing alt-text is never overwritten.

= How do I customize the alt-text template? =

Go to **Smart Gallery > EXIF & SEO Settings** and modify the template using variables like `{description}`, `{camera}`, `{date}`, and `{location}`.

= Can I use my own lightbox plugin? =

Yes! Set **Link Behavior** to "None" or "Direct Link" and use your preferred lightbox plugin.

= Is this plugin compatible with caching plugins? =

Yes. Smart Gallery Optimizer is compatible with popular caching plugins like WP Super Cache, W3 Total Cache, and WP Rocket.

= Does this work with WordPress Multisite? =

Yes. The plugin is multisite compatible.

= Is the plugin translation ready? =

Yes. The plugin uses WordPress i18n functions and is ready for translation. Text domain: `smart-gallery-optimizer`

= What about performance impact? =

Image conversion happens only during upload (one-time processing). After conversion, the plugin improves performance with smaller file sizes and lazy loading.

== Screenshots ==

1. **Gallery Manager Interface** - Visual gallery creation with drag-and-drop image reordering, settings configuration, and one-click shortcode copy.

2. **Gallery List Page** - View all saved galleries with image count, settings, shortcode, and action buttons (edit, delete, duplicate).

3. **Admin Settings Page** - Configure WebP/AVIF conversion, lazy loading, responsive grid, and default columns. Server capabilities displayed with status indicators.

4. **EXIF & SEO Settings** - Enable auto alt-text generation, customize template with variables, and include camera/date/location info.

5. **Link Behavior Settings** - Choose default link type (none, direct, lightbox), configure new tab behavior, and set lightbox title/caption display.

6. **Bulk Alt-Text Generator** - Preview and generate alt-text for up to 100 images at once. Shows thumbnail, filename, and generated alt-text.

7. **Frontend Gallery Display** - Responsive 3-column gallery with lazy loading, hover effects, and mobile optimization. Automatically adapts to screen size.

8. **PhotoSwipe Lightbox** - Full-screen image viewing with touch support, zoom, navigation, and optional titles/captions.

9. **Server Capabilities Check** - View which features your server supports (GD Library, WebP, AVIF, EXIF) with visual status indicators.

10. **Responsive Mobile View** - Gallery automatically becomes single column on mobile devices for optimal viewing experience.

== Changelog ==

= 1.0.0 - 2024-01-15 =

**Image Optimization**
* Added: Automatic WebP conversion on upload
* Added: AVIF conversion support (PHP 8.1+ required)
* Added: Quality control for WebP and AVIF (1-100)
* Added: Server capability detection
* Added: Original image preservation

**Performance & Display**
* Added: Lazy loading with Intersection Observer API
* Added: Responsive CSS Grid layouts (2-6 columns)
* Added: [smart_gallery] shortcode
* Added: Mobile optimization (automatic single column)
* Added: Conditional asset loading
* Added: Minified CSS and JavaScript

**Gallery Management**
* Added: Custom post type for galleries
* Added: Visual gallery manager interface
* Added: Drag-and-drop image reordering
* Added: Save, edit, delete, duplicate galleries
* Added: WordPress Media Library integration
* Added: Per-gallery settings
* Added: Copy shortcode to clipboard

**PhotoSwipe Lightbox**
* Added: PhotoSwipe v5.4.4 integration
* Added: Touch-friendly interface
* Added: Pinch-to-zoom support
* Added: Swipe navigation
* Added: Keyboard navigation
* Added: Optional titles and captions
* Added: Full-screen viewing

**EXIF & SEO Features**
* Added: Automatic EXIF metadata extraction
* Added: Auto-generate SEO-friendly alt-text
* Added: Customizable alt-text templates
* Added: Camera, date, location data support
* Added: Bulk alt-text generator
* Added: Filename-based fallback

**Admin Interface**
* Added: Main settings page with 4 sections
* Added: Gallery list page
* Added: Gallery editor page
* Added: Bulk alt-text generator page
* Added: Server capabilities display
* Added: Toggle switches and sliders

**WordPress Integration**
* Added: WordPress 5.0+ compatibility
* Added: PHP 8.0+ support
* Added: Translation ready (i18n)
* Added: Multisite compatible
* Added: Theme compatible
* Added: Page builder support

**Security**
* Added: CSRF protection with consistent nonce verification
* Added: WordPress.org standard nonce naming (sgo_gallery_nonce)
* Added: Capability checks (manage_options) on all admin functions
* Added: Input sanitization with Yoda conditions
* Added: $_SERVER variable sanitization
* Added: Path traversal prevention with realpath() validation
* Added: Directory protection with index.php files
* Added: Secure file operations (RecursiveDirectoryIterator)
* Added: Conditional error logging (WP_DEBUG checks)
* Added: Output escaping on all displays
* Added: SQL injection prevention with prepared statements
* Added: WordPress Coding Standards compliance

**Documentation**
* Added: README.md
* Added: INSTALLATION-GUIDE.md
* Added: USER-GUIDE.md
* Added: DEVELOPER-GUIDE.md
* Added: CHANGELOG.md

= Future Enhancements =

**Planned for v1.1.0**
* Bulk conversion tool for existing images
* Conversion statistics dashboard
* Additional format support
* Performance monitoring

**Planned for v1.2.0**
* Advanced compression options
* CDN integration
* Image optimization recommendations
* Automatic image resizing

== Upgrade Notice ==

= 1.0.0 =
Initial release. Includes WebP/AVIF conversion, lazy loading, responsive galleries, PhotoSwipe lightbox, EXIF extraction, and auto alt-text generation.

== Support ==

For support, feature requests, or bug reports:

* **Author:** Sabibur Rahman
* **Fiverr:** https://www.fiverr.com/sabibur
* **Plugin URI:** https://example.com/smart-gallery-optimizer

== Privacy Policy ==

Smart Gallery Optimizer does not collect, store, or transmit any personal data. All image processing happens locally on your server.

**What data is stored:**
* Plugin settings (in WordPress options table)
* Gallery configurations (in WordPress posts table)
* EXIF metadata (in WordPress post meta)
* Generated alt-text (in WordPress post meta)

**What data is NOT collected:**
* User information
* Analytics data
* External API calls
* Third-party tracking

All data remains on your WordPress installation.

== Credits ==

**Developed by:** Sabibur Rahman

**Third-Party Libraries:**
* PhotoSwipe v5.4.4 (MIT License) - https://photoswipe.com

**Built With:**
* WordPress Plugin API
* PHP GD Library
* JavaScript (ES6)
* CSS Grid
* Intersection Observer API

== License ==

This plugin is licensed under the GPL v2 or later.

Smart Gallery Optimizer WordPress Plugin
Copyright (C) 2024 Sabibur Rahman

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
