Skip to content

Commit 6a455f7

Browse files
committed
Merge pull request #1 from lazy-ants/tiff_format
Added tiff formats and ignore case on formats
2 parents 78e5aac + e8d89b5 commit 6a455f7

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

project/src/main.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ lazy_static! {
2525

2626
fn main() {
2727
fn handler(req: &mut Request) -> IronResult<Response> {
28-
let regex = Regex::new(r"^transform/(.+)/(.+)\.(jpg|png)$").unwrap();
28+
let regex = Regex::new(r"^transform/(.+)/(.+)\.(?i)(jpg|jpeg|png|tif|tiff)$").unwrap();
2929
match regex.captures(&req.url.path.join("/")) {
3030
Some(cap) => {
3131
let ext = cap.at(3).unwrap();
@@ -58,17 +58,18 @@ fn handle_image(filters: &str, path: &str, ext: &str) -> IronResult<Response> {
5858
}
5959

6060
let mut buffer = VectorOfuchar::new();
61-
let mut mat = highgui::imread(path, highgui::IMREAD_COLOR).unwrap();
61+
let mut mat = highgui::imread(path, highgui::IMREAD_UNCHANGED).unwrap();
6262

6363
for operation in &operations {
6464
mat = operation.apply(&mat);
6565
}
6666

6767
highgui::imencode(&format!(".{}", ext), &mat, &mut buffer, &VectorOfint::new());
6868

69-
let content_type = match ext {
70-
"jpg" => "image/jpeg",
69+
let content_type = match String::from(ext).to_lowercase().as_ref() {
70+
"jpg"|"jpeg" => "image/jpeg",
7171
"png" => "image/png",
72+
"tif"|"tiff" => "image/tiff",
7273
_ => "text/plain"
7374
}.parse::<Mime>().unwrap();
7475

0 commit comments

Comments
 (0)