You can customize the reducer by inheriting from the ImageBlobReduce class, adding hooks, or overriding internal methods on an instance.
Example: Force output to always be JPEG with 0.8 quality
import imageBlobReduce from 'image-blob-reduce'
const reducer = imageBlobReduce()
reducer._create_blob = function (env) {
return this.pica.toBlob(env.out_canvas, 'image/jpeg', 0.8)
.then(function (blob) {
env.out_blob = blob
return env
})
}
Example: Rewrite scaling logic to use a min option
import imageBlobReduce from 'image-blob-reduce'
const reducer = imageBlobReduce()
reducer._calculate_size = function (env) {
const scale_factor = env.opts.min / Math.min(env.image.width, env.image.height)
if (scale_factor > 1) scale_factor = 1
env.transform_width = Math.max(Math.round(env.image.width * scale_factor), 1)
env.transform_height = Math.max(Math.round(env.image.height * scale_factor), 1)
return env
}