Skip to content

Commit

Permalink
Fixed cache regeneration for changed files
Browse files Browse the repository at this point in the history
  • Loading branch information
lamka02sk committed Jun 16, 2024
1 parent 1d5ff1e commit 2a61acb
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 14 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "picturium"
version = "0.1.0"
version = "0.1.1"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
6 changes: 3 additions & 3 deletions src/pipeline/finalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ fn avif_default_quality(image: &VipsImage) -> i32 {
let area = width * height / 1000000.0;

// Dynamic AVIF quality based on image area, min. 40, max. 59
let quality = (8.0 - area) * (59.0 - 40.0) / (8.0 - 0.25) + 40.0;
let quality = (8.0 - area).clamp(0.0, 8.0 - 0.25) * (59.0 - 40.0) / (8.0 - 0.25) + 40.0;
debug!("Serving image with quality: {}%, {area}MPix", quality as i32);

quality as i32
Expand All @@ -148,7 +148,7 @@ fn webp_default_quality(image: &VipsImage) -> i32 {
let area = width * height / 1000000.0;

// Dynamic WebP quality based on image area, min. 16, max. 78
let quality = (8.0 - area) * (78.0 - 16.0) / (8.0 - 0.25) + 16.0;
let quality = (8.0 - area).clamp(0.0, 8.0 - 0.25) * (78.0 - 16.0) / (8.0 - 0.25) + 16.0;
debug!("Serving image with quality: {}%, {area}MPix", quality as i32);

quality as i32
Expand All @@ -162,7 +162,7 @@ fn jpg_default_quality(image: &VipsImage) -> i32 {
let area = width * height / 1000000.0;

// Dynamic JPEG quality based on image area, min. 40, max. 75
let quality = (8.0 - area) * (75.0 - 40.0) / (8.0 - 0.25) + 40.0;
let quality = (8.0 - area).clamp(0.0, 8.0 - 0.25) * (75.0 - 40.0) / (8.0 - 0.25) + 40.0;
debug!("Serving image with quality: {}%, {area}MPix", quality as i32);

quality as i32
Expand Down
5 changes: 3 additions & 2 deletions src/pipeline/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use std::path::PathBuf;

use log::debug;
use crate::cache;

use crate::cache;
use crate::parameters::{Rotate, UrlParameters};
use crate::services::formats::{is_svg, supports_transparency, OutputFormat};
use crate::services::formats::{is_svg, OutputFormat, supports_transparency};

mod thumbnail;
mod rotate;
Expand Down
10 changes: 5 additions & 5 deletions src/pipeline/thumbnail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ use std::path::{Path, PathBuf};
use std::process::Command;

use libvips::{ops, VipsImage};
use libvips::ops::{Intent, Interesting, ThumbnailOptions};
use libvips::ops::{Access, Intent, Interesting, ThumbnailOptions};

use crate::cache;
use crate::cache::{get_document_path_from_url_parameters, index};

use crate::parameters::UrlParameters;
use crate::pipeline::{PipelineError, PipelineResult};
use crate::pipeline::resize::get_rasterize_dimensions;
Expand All @@ -16,7 +16,7 @@ use crate::services::vips::get_error_message;
pub(crate) async fn run(working_file: &Path, url_parameters: &UrlParameters<'_>) -> PipelineResult<VipsImage> {

if !is_thumbnail_format(url_parameters.path) {
return match VipsImage::new_from_file(&working_file.to_string_lossy()) {
return match VipsImage::new_from_file_access(&working_file.to_string_lossy(), Access::Sequential, true) {
Ok(image) => Ok(image),
Err(error) => return Err(PipelineError(format!("Failed to open image: {}", error)))
};
Expand All @@ -37,10 +37,10 @@ pub(crate) async fn run(working_file: &Path, url_parameters: &UrlParameters<'_>)

fn generate_pdf_thumbnail(working_file: &Path, url_parameters: &UrlParameters<'_>) -> PipelineResult<VipsImage> {

let pdf = VipsImage::new_from_file(&working_file.to_string_lossy()).unwrap();
let pdf = VipsImage::new_from_file_access(&working_file.to_string_lossy(), Access::Sequential, true).unwrap();
let page_parameter = format!("[page={}]", (url_parameters.thumbnail.page - 1).min(pdf.get_n_pages() as u32 - 1));

let pdf = VipsImage::new_from_file(&(working_file.to_string_lossy() + &page_parameter[..])).unwrap();
let pdf = VipsImage::new_from_file_access(&(working_file.to_string_lossy() + &page_parameter[..]), Access::Sequential, true).unwrap();
let (width, height) = get_rasterize_dimensions(&pdf, url_parameters);

match ops::thumbnail_with_opts(&(working_file.to_string_lossy() + &page_parameter[..]), width, &ThumbnailOptions {
Expand Down

0 comments on commit 2a61acb

Please sign in to comment.