Download the PHP package firstinternet/wordpress-responsive-image without Composer
On this page you can find all versions of the php package firstinternet/wordpress-responsive-image. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download firstinternet/wordpress-responsive-image
More information about firstinternet/wordpress-responsive-image
Files in firstinternet/wordpress-responsive-image
Package wordpress-responsive-image
Short Description Generate responsive Wordpress images. Supports .webp, lazyload, bootstrap.
License proprietary
Homepage https://bitbucket.org/firstint/wordpress-responsive-image
Informations about the package wordpress-responsive-image
First Internet Responsive Image Class
Overview
The responsive image class was built by a team of developers at First Internet.
The ResponsiveImage class is a PHP utility designed to generate responsive images for WordPress. It supports multiple image sources, lazy loading, WebP format, and dynamic sizing based on Bootstrap-like breakpoints.
Features
- Responsive Image Handling: Supports multiple image sizes for different breakpoints.
- Lazy Loading: Optionally enables lazy loading for performance optimization.
- WebP Support: Automatically replaces image formats with WebP versions if enabled.
- Custom Attributes: Allows adding custom attributes like classes, alt text, and inline styles.
- Automatic Sizing: Can determine image sizes dynamically based on Bootstrap column classes.
- WordPress Integration: Works with WordPress media library functions.
Installation
Ensure that your WordPress theme or plugin includes this class and that you have the necessary WordPress functions available.
- Copy the
ResponsiveImage.phpfile into your theme or plugin. - Include it in your project:
Usage
Basic Example
This outputs a responsive <picture> element for the image with ID 123, using the medium size.
Customizing Output
Using get() Instead of generate()
If you need to store the image markup in a variable:
Methods
__construct(int $imageId, string $size = 'full')
- $imageId (int) - WordPress attachment ID.
- $size (string, optional) - Image size (default:
'full').
setSources(array $sources)
Sets different image sources for various breakpoints.
lazyLoad(string $lazyClass = 'lazy')
Enables lazy loading by default with the 'lazy' class.
webp()
Enables WebP format support.
setClass(string $class)
Adds custom classes to the <img> element.
setAlt(string $alt)
Sets the image alt text.
setAttributes(array $attributes)
Adds custom attributes to the <img> element.
setSizes(string $sizes)
Sets the sizes attribute manually.
autoSizes(string $classes)
Automatically calculates image sizes based on Bootstrap grid classes.
generate()
Outputs the <picture> element directly.
get()
Returns the <picture> element as a string.
Example Output
License
This project is licensed under the MIT License - see the LICENSE file for details.
This class provides a flexible way to manage responsive images in WordPress, improving performance and user experience.
For more information, visit First Internet.