diff --git a/Changes b/Changes index 03ef689..95b1050 100644 --- a/Changes +++ b/Changes @@ -23,6 +23,10 @@ Extended features: o Rectangle may be specified as x y x' y' rather than x y w h +Fixes: + +o -image-resolution-json was listing all images + * = Supported by a grant from NLnet 2.7.1 (July 2024) diff --git a/cpdfcommand.ml b/cpdfcommand.ml index dd190c7..c7512a2 100644 --- a/cpdfcommand.ml +++ b/cpdfcommand.ml @@ -4405,8 +4405,7 @@ let go () = let images = Cpdfimage.image_resolution pdf range f in iter (function (pagenum, xobject, w, h, wdpi, hdpi, objnum) -> - if wdpi < f || hdpi < f then - Printf.printf "%i, %s, %i, %i, %f, %f, %i\n" pagenum xobject w h wdpi hdpi objnum) + Printf.printf "%i, %s, %i, %i, %f, %f, %i\n" pagenum xobject w h wdpi hdpi objnum) images | Some ListImages -> let pdf = get_single_pdf args.op true in diff --git a/cpdfimage.ml b/cpdfimage.ml index 72b6d53..4804e07 100644 --- a/cpdfimage.ml +++ b/cpdfimage.ml @@ -193,7 +193,7 @@ type xobj = let image_results = ref [] -let rec image_resolution_page pdf page pagenum dpi images = +let rec image_resolution_page pdf page pagenum images = try let pageops = Pdfops.parse_operators pdf page.Pdfpage.resources page.Pdfpage.content and transform = ref [ref Pdftransform.i_matrix] in @@ -239,7 +239,7 @@ let rec image_resolution_page pdf page pagenum dpi images = Pdfpage.rest = Pdf.Dictionary []} in let newpdf = Pdfpage.change_pages false pdf [page] in - image_resolution newpdf [pagenum] dpi + image_resolution newpdf [pagenum] | (pagenum, name, Image (w, h), objnum) -> let lx = Pdfunits.inches (distance_between o x) Pdfunits.PdfPoint in let ly = Pdfunits.inches (distance_between o y) Pdfunits.PdfPoint in @@ -268,7 +268,7 @@ let rec image_resolution_page pdf page pagenum dpi images = with e -> Printf.printf "Error %s\n" (Printexc.to_string e); flprint "\n" -and image_resolution pdf range dpi = +and image_resolution pdf range = let images = ref [] in Cpdfpage.iter_pages (fun pagenum page -> @@ -322,13 +322,16 @@ and image_resolution pdf range dpi = iter (function (pagenum, images) -> let page = select pagenum pages in - image_resolution_page pdf page pagenum dpi images) + image_resolution_page pdf page pagenum images) pagesplits +let is_below_dpi dpi (_, _, _, _, wdpi, hdpi, _) = + wdpi < dpi || hdpi < dpi + let image_resolution pdf range dpi = image_results := []; - image_resolution pdf range dpi; - rev !image_results + image_resolution pdf range; + rev (keep (is_below_dpi dpi) !image_results) let image_resolution_json pdf range dpi = let images = image_resolution pdf range dpi in