Skip to content

Commit fee3bc8

Browse files
committed
support orientation
1 parent 34b0a6b commit fee3bc8

File tree

12 files changed

+242
-113
lines changed

12 files changed

+242
-113
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "image-convert"
3-
version = "0.19.0"
3+
version = "0.20.0"
44
authors = ["Magic Len <len@magiclen.org>"]
55
edition = "2021"
66
rust-version = "1.70"
@@ -16,7 +16,7 @@ include = ["src/**/*", "Cargo.toml", "README.md", "LICENSE"]
1616
regex = "1"
1717
once_cell = "1"
1818
str-utils = "0.1"
19-
ico = "0.3"
19+
ico = "0.4"
2020
magick_rust = "1.0"
2121

2222
[features]

src/format_bmp.rs

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,23 @@ use crate::{
1010
/// The output config of a BMP image.
1111
pub struct BMPConfig {
1212
/// Remove the metadata stored in the input image.
13-
pub strip_metadata: bool,
13+
pub strip_metadata: bool,
1414
/// The width of the output image. `0` means the original width.
15-
pub width: u16,
15+
pub width: u16,
1616
/// The height of the output image. `0` means the original height.
17-
pub height: u16,
17+
pub height: u16,
1818
/// Crop the image.
19-
pub crop: Option<Crop>,
19+
pub crop: Option<Crop>,
2020
/// Only shrink the image, not to enlarge it.
21-
pub shrink_only: bool,
21+
pub shrink_only: bool,
2222
/// The higher the sharper. A negative value means auto adjustment.
23-
pub sharpen: f64,
23+
pub sharpen: f64,
24+
/// Apply orientation from image metadata if available.
25+
pub respect_orientation: bool,
2426
/// The color is used for fill up the alpha background.
25-
pub background_color: Option<ColorName>,
27+
pub background_color: Option<ColorName>,
2628
/// Pixels per inch.
27-
pub ppi: Option<(f64, f64)>,
29+
pub ppi: Option<(f64, f64)>,
2830
}
2931

3032
impl BMPConfig {
@@ -37,21 +39,23 @@ impl BMPConfig {
3739
/// crop: None,
3840
/// shrink_only: true,
3941
/// sharpen: -1f64,
42+
/// respect_orientation: false,
4043
/// background_color: None,
4144
/// ppi: None,
4245
/// }
4346
/// ```
4447
#[inline]
4548
pub const fn new() -> BMPConfig {
4649
BMPConfig {
47-
strip_metadata: true,
48-
width: 0u16,
49-
height: 0u16,
50-
crop: None,
51-
shrink_only: true,
52-
sharpen: -1f64,
53-
background_color: None,
54-
ppi: None,
50+
strip_metadata: true,
51+
width: 0u16,
52+
height: 0u16,
53+
crop: None,
54+
shrink_only: true,
55+
sharpen: -1f64,
56+
respect_orientation: false,
57+
background_color: None,
58+
ppi: None,
5559
}
5660
}
5761
}
@@ -93,6 +97,11 @@ impl ImageConfig for BMPConfig {
9397
fn is_shrink_only(&self) -> bool {
9498
self.shrink_only
9599
}
100+
101+
#[inline]
102+
fn respect_orientation(&self) -> bool {
103+
self.respect_orientation
104+
}
96105
}
97106

98107
/// Convert an image to a BMP image.

src/format_gif.rs

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,19 @@ use crate::{
99
/// The output config of a GIF image.
1010
pub struct GIFConfig {
1111
/// Remove the metadata stored in the input image.
12-
pub strip_metadata: bool,
12+
pub strip_metadata: bool,
1313
/// The width of the output image. `0` means the original width.
14-
pub width: u16,
14+
pub width: u16,
1515
/// The height of the output image. `0` means the original height.
16-
pub height: u16,
16+
pub height: u16,
1717
/// Crop the image.
18-
pub crop: Option<Crop>,
18+
pub crop: Option<Crop>,
1919
/// Only shrink the image, not to enlarge it.
20-
pub shrink_only: bool,
20+
pub shrink_only: bool,
2121
/// The higher the sharper. A negative value means auto adjustment.
22-
pub sharpen: f64,
22+
pub sharpen: f64,
23+
/// Apply orientation from image metadata if available.
24+
pub respect_orientation: bool,
2325
}
2426

2527
impl GIFConfig {
@@ -31,18 +33,20 @@ impl GIFConfig {
3133
/// height: 0u16,
3234
/// crop: None,
3335
/// shrink_only: true,
36+
/// respect_orientation: false,
3437
/// sharpen: -1f64,
3538
/// }
3639
/// ```
3740
#[inline]
3841
pub const fn new() -> GIFConfig {
3942
GIFConfig {
40-
strip_metadata: true,
41-
width: 0u16,
42-
height: 0u16,
43-
crop: None,
44-
shrink_only: true,
45-
sharpen: -1f64,
43+
strip_metadata: true,
44+
width: 0u16,
45+
height: 0u16,
46+
crop: None,
47+
shrink_only: true,
48+
respect_orientation: false,
49+
sharpen: -1f64,
4650
}
4751
}
4852
}
@@ -84,6 +88,11 @@ impl ImageConfig for GIFConfig {
8488
fn is_shrink_only(&self) -> bool {
8589
self.shrink_only
8690
}
91+
92+
#[inline]
93+
fn respect_orientation(&self) -> bool {
94+
self.respect_orientation
95+
}
8796
}
8897

8998
/// Convert an image to a GIF image.

src/format_gray_raw.rs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,17 @@ use crate::{
1010
/// The output config of a RAW image with gray colors.
1111
pub struct GrayRawConfig {
1212
/// Remove the metadata stored in the input image.
13-
pub strip_metadata: bool,
13+
pub strip_metadata: bool,
1414
/// The width of the output image. `0` means the original width.
15-
pub width: u16,
15+
pub width: u16,
1616
/// The height of the output image. `0` means the original height.
17-
pub height: u16,
17+
pub height: u16,
1818
/// Crop the image.
19-
pub crop: Option<Crop>,
19+
pub crop: Option<Crop>,
20+
/// Apply orientation from image metadata if available.
21+
pub respect_orientation: bool,
2022
/// The color is used for fill up the alpha background.
21-
pub background_color: Option<ColorName>,
23+
pub background_color: Option<ColorName>,
2224
}
2325

2426
impl GrayRawConfig {
@@ -29,17 +31,19 @@ impl GrayRawConfig {
2931
/// width: 0u16,
3032
/// height: 0u16,
3133
/// crop: None,
34+
/// respect_orientation: false,
3235
/// background_color: None,
3336
/// }
3437
/// ```
3538
#[inline]
3639
pub const fn new() -> GrayRawConfig {
3740
GrayRawConfig {
38-
strip_metadata: true,
39-
width: 0u16,
40-
height: 0u16,
41-
crop: None,
42-
background_color: None,
41+
strip_metadata: true,
42+
width: 0u16,
43+
height: 0u16,
44+
crop: None,
45+
respect_orientation: false,
46+
background_color: None,
4347
}
4448
}
4549
}
@@ -81,6 +85,11 @@ impl ImageConfig for GrayRawConfig {
8185
fn is_shrink_only(&self) -> bool {
8286
true
8387
}
88+
89+
#[inline]
90+
fn respect_orientation(&self) -> bool {
91+
self.respect_orientation
92+
}
8493
}
8594

8695
/// Convert an image to a RAW image with gray colors.

src/format_ico.rs

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ use crate::{compute_output_size_sharpen, fetch_magic_wand, Crop, ImageConfig, Im
55

66
#[derive(Debug)]
77
struct ICOConfigInner {
8-
strip_metadata: bool,
9-
width: u16,
10-
height: u16,
11-
crop: Option<Crop>,
12-
shrink_only: bool,
13-
sharpen: f64,
8+
strip_metadata: bool,
9+
width: u16,
10+
height: u16,
11+
crop: Option<Crop>,
12+
shrink_only: bool,
13+
sharpen: f64,
14+
respect_orientation: bool,
1415
}
1516

1617
impl ICOConfigInner {
@@ -25,6 +26,7 @@ impl ICOConfigInner {
2526
crop: config.crop,
2627
shrink_only: false,
2728
sharpen: config.sharpen,
29+
respect_orientation: config.respect_orientation,
2830
});
2931
}
3032

@@ -36,13 +38,15 @@ impl ICOConfigInner {
3638
/// The output config of an ICO image.
3739
pub struct ICOConfig {
3840
/// Remove the metadata stored in the input image.
39-
pub strip_metadata: bool,
41+
pub strip_metadata: bool,
4042
/// The size of the output image, made up of a width and a height. `0` means the original width or the original height.
41-
pub size: Vec<(u16, u16)>,
43+
pub size: Vec<(u16, u16)>,
4244
/// Crop the image.
43-
pub crop: Option<Crop>,
45+
pub crop: Option<Crop>,
4446
/// The higher the sharper. A negative value means auto adjustment.
45-
pub sharpen: f64,
47+
pub sharpen: f64,
48+
/// Apply orientation from image metadata if available.
49+
pub respect_orientation: bool,
4650
}
4751

4852
impl ICOConfig {
@@ -53,15 +57,17 @@ impl ICOConfig {
5357
/// size: Vec::with_capacity(1),
5458
/// crop: None,
5559
/// sharpen: -1f64,
60+
/// respect_orientation: false,
5661
/// }
5762
/// ```
5863
#[inline]
5964
pub fn new() -> ICOConfig {
6065
ICOConfig {
61-
strip_metadata: true,
62-
size: Vec::with_capacity(1),
63-
crop: None,
64-
sharpen: -1f64,
66+
strip_metadata: true,
67+
size: Vec::with_capacity(1),
68+
crop: None,
69+
sharpen: -1f64,
70+
respect_orientation: false,
6571
}
6672
}
6773
}
@@ -103,6 +109,11 @@ impl ImageConfig for ICOConfigInner {
103109
fn is_shrink_only(&self) -> bool {
104110
self.shrink_only
105111
}
112+
113+
#[inline]
114+
fn respect_orientation(&self) -> bool {
115+
self.respect_orientation
116+
}
106117
}
107118

108119
/// Convert an image to an ICO image.

src/format_jpeg.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ pub struct JPGConfig {
2121
pub shrink_only: bool,
2222
/// The higher the sharper. A negative value means auto adjustment.
2323
pub sharpen: f64,
24+
/// Apply orientation from image metadata if available.
25+
pub respect_orientation: bool,
2426
/// Use 4:2:0 (chroma quartered) subsampling to reduce the file size.
2527
pub force_to_chroma_quartered: bool,
2628
/// From 1 to 100, the higher the better.
@@ -41,6 +43,7 @@ impl JPGConfig {
4143
/// crop: None,
4244
/// shrink_only: true,
4345
/// sharpen: -1f64,
46+
/// respect_orientation: false,
4447
/// force_to_chroma_quartered: true,
4548
/// quality: 85u8,
4649
/// background_color: None,
@@ -56,6 +59,7 @@ impl JPGConfig {
5659
crop: None,
5760
shrink_only: true,
5861
sharpen: -1f64,
62+
respect_orientation: false,
5963
force_to_chroma_quartered: true,
6064
quality: 85u8,
6165
background_color: None,
@@ -101,6 +105,11 @@ impl ImageConfig for JPGConfig {
101105
fn is_shrink_only(&self) -> bool {
102106
self.shrink_only
103107
}
108+
109+
#[inline]
110+
fn respect_orientation(&self) -> bool {
111+
self.respect_orientation
112+
}
104113
}
105114

106115
/// Convert an image to a JPEG image.

0 commit comments

Comments
 (0)