Apply output DPI to JPEG files via mozjpeg pixel density
- Add output_dpi field to EncoderOptions - Set JFIF pixel density header in JPEG output when DPI > 0 - Wire output_dpi from ProcessingJob through to encoder in both parallel and sequential execution paths
This commit is contained in:
@@ -8,6 +8,8 @@ use crate::types::{ImageFormat, QualityPreset};
|
|||||||
pub struct EncoderOptions {
|
pub struct EncoderOptions {
|
||||||
pub progressive_jpeg: bool,
|
pub progressive_jpeg: bool,
|
||||||
pub avif_speed: u8,
|
pub avif_speed: u8,
|
||||||
|
/// Output DPI (0 means don't set / use default)
|
||||||
|
pub output_dpi: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct OutputEncoder {
|
pub struct OutputEncoder {
|
||||||
@@ -20,6 +22,7 @@ impl OutputEncoder {
|
|||||||
options: EncoderOptions {
|
options: EncoderOptions {
|
||||||
progressive_jpeg: false,
|
progressive_jpeg: false,
|
||||||
avif_speed: 6,
|
avif_speed: 6,
|
||||||
|
output_dpi: 0,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -80,6 +83,13 @@ impl OutputEncoder {
|
|||||||
if self.options.progressive_jpeg {
|
if self.options.progressive_jpeg {
|
||||||
comp.set_progressive_mode();
|
comp.set_progressive_mode();
|
||||||
}
|
}
|
||||||
|
if self.options.output_dpi > 0 {
|
||||||
|
comp.set_pixel_density(mozjpeg::PixelDensity {
|
||||||
|
unit: mozjpeg::PixelDensityUnit::Inches,
|
||||||
|
x: self.options.output_dpi as u16,
|
||||||
|
y: self.options.output_dpi as u16,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
let mut output = Vec::new();
|
let mut output = Vec::new();
|
||||||
let mut started = comp.start_compress(&mut output).map_err(|e| PixstripError::Processing {
|
let mut started = comp.start_compress(&mut output).map_err(|e| PixstripError::Processing {
|
||||||
|
|||||||
@@ -185,6 +185,7 @@ impl PipelineExecutor {
|
|||||||
let encoder = OutputEncoder::with_options(EncoderOptions {
|
let encoder = OutputEncoder::with_options(EncoderOptions {
|
||||||
progressive_jpeg: job.progressive_jpeg,
|
progressive_jpeg: job.progressive_jpeg,
|
||||||
avif_speed: job.avif_speed,
|
avif_speed: job.avif_speed,
|
||||||
|
output_dpi: job.output_dpi,
|
||||||
});
|
});
|
||||||
|
|
||||||
match Self::process_single_static(job, source, &loader, &encoder, idx) {
|
match Self::process_single_static(job, source, &loader, &encoder, idx) {
|
||||||
@@ -243,6 +244,7 @@ impl PipelineExecutor {
|
|||||||
let encoder = OutputEncoder::with_options(EncoderOptions {
|
let encoder = OutputEncoder::with_options(EncoderOptions {
|
||||||
progressive_jpeg: job.progressive_jpeg,
|
progressive_jpeg: job.progressive_jpeg,
|
||||||
avif_speed: job.avif_speed,
|
avif_speed: job.avif_speed,
|
||||||
|
output_dpi: job.output_dpi,
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut result = BatchResult {
|
let mut result = BatchResult {
|
||||||
|
|||||||
Reference in New Issue
Block a user