Skip to content

Commit

Permalink
feat(turbopack-image): enable a few more image formats (#5211)
Browse files Browse the repository at this point in the history
### Description

Part of WEB-1146.
  • Loading branch information
kwonoj authored Jun 5, 2023
1 parent 5ffa722 commit fec57b5
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions crates/turbopack-image/src/process/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use anyhow::{bail, Context, Result};
use base64::{display::Base64Display, engine::general_purpose::STANDARD};
use image::{
codecs::{
bmp::BmpEncoder,
ico::IcoEncoder,
jpeg::JpegEncoder,
png::{CompressionType, PngEncoder},
},
Expand Down Expand Up @@ -190,6 +192,25 @@ fn encode_image(image: DynamicImage, format: ImageFormat, quality: u8) -> Result
)?;
(buf, mime::IMAGE_JPEG)
}
ImageFormat::Ico => {
IcoEncoder::new(&mut buf).write_image(
image.as_bytes(),
width,
height,
image.color(),
)?;
// mime does not support typed IMAGE_X_ICO yet
(buf, Mime::from_str("image/x-icon")?)
}
ImageFormat::Bmp => {
BmpEncoder::new(&mut buf).write_image(
image.as_bytes(),
width,
height,
image.color(),
)?;
(buf, mime::IMAGE_BMP)
}
#[cfg(feature = "webp")]
ImageFormat::WebP => {
use image::codecs::webp::{WebPEncoder, WebPQuality};
Expand Down

0 comments on commit fec57b5

Please sign in to comment.