A better way of generating images code side, for WordPress.
$image; // Set to an image array, id, or local url
echo new bi($image)->resize()->width(500)->blur(10)->go();
You don't have to define the resize method (resize, constrain), or the width or height if you only want to pass the image through some filters
new bi($image);
The first function you will use when creating a BetterImage. $image
can be set to a WP image array, ID, or a local url (remote files are currently not supported).
bi()->resize();
Sets the method to resize (the default)
- Setting both the width and height will stretch the image (if the aspect ratio is different)
- You can upscale the image
- Leaving either (not both) the width or height values unset, or 'auto' will scale the image keeping the original aspect ratio
bi()->constrain();
Sets the method to constrain
- The image will resized and cropped to fit within the defined width and height
bi()->width(500);
Sets the width of the new image
bi()->height(500);
Sets the height of the new image
bi()->invert();
Invert the colours of the image
bi()->grayscale();
Make the image grayscale (black and white)
bi()->brightness(100);
Set the brightness of the image
- Minimum Brightness (darkest): -255
- No Change: 0
- Maximum Brightness (lightest): 255
int $level
The level of brightness (min: -255, max: 255)
bi()->contrast(100);
Set the contrast level of the image (Note the direction, it is opposite to brightness)
- Minimum Contrast: 100
- No Change: 0
- Maximum Contrast: -100
int $level
The level of contrast (min: 100, max: -100)
bi()->colorize(255, 0, 0, 0);
Colorizes the image
- Red, Green, & Blue values range from -255 to 255, where 0 is no change
- Alpha values range from 0 (opaque) to 127 (transparent)
- The alpha value effects the strength of the colorize effect, not the image itself
int $red
The red value (min: -255, max: 255)int $green
The green value (min: -255, max: 255)int $blue
The blue value (min: -255, max: 255)int $alpha
The alpha value (min/opaque: 0, max/transparent: 127)
bi()->edgedetect();
Highlights the edges of objects in the image on a gray background
bi()->emboss();
Creates an emboss effect on the edges of objects in the image, on a gray background
bi()->blur(10, 'selective');
Blurs the image
- Defaults to gaussian blur
gaussian
is a traditional blurselective
is much smootherint $amount
The number of times the image is passed through the blur filterstring $type
The type of blur (gaussian, selective)
bi()->sharpen();
Creates a sharper image via mean removal
bi()->smooth(10);
Smooths the image
- Applies a 9-cell convolution matrix where center pixel has the weight $amount and others weight of 1.0.
- The result is normalized by dividing the sum with $amount + 8.0 (sum of the matrix).
- Any float is accepted, large values (in practice: 2048 or more) = no change
float $amount
The amount of smoothing
bi()->pixelate(25, true);
Pixelate the image
int $pixel_size
The block size in pxbool $use_advanced
Whether or not to use the advanced pixelation effect (default: false)
bi()->go();
The last function you run in the BetterImages function chain. It triggers all the image manipulations and returns the new image URL.
bool $force_image_re_save
Re-save the image, even if it already exists (cache breaking)