SVG-Compression Profile balanced ist wesentlich konservativer, Datei-Eigenschaften der neuen PPTX enthält Hinweis auf PPTX Image Compressor in den Kommentaren
This commit is contained in:
+51
-14
@@ -2,7 +2,11 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
PPTX Raster & Vector Komprimier-Tool (Raster-Iamges: via CaesiumCLT, Vector-Images: via python Module svg_polish)
|
||||
Version: 1.1.8
|
||||
Version: 1.1.9
|
||||
|
||||
Änderungen in 1.1.9
|
||||
- SVG Files Default Profile: `balanced` statt `aggressive`
|
||||
- Datei-Eigenschaften der neu generierten PPTX enthält Hinweis auf Compression `compressed by PPTX Image Compressor`
|
||||
|
||||
Änderungen in 1.1.8:
|
||||
- SVG Files werden bei Vorhandensein von svg_polish anhand von 2 Profilen optimiert: balanced|agressive
|
||||
@@ -38,7 +42,7 @@ from typing import Callable, List, Optional
|
||||
|
||||
|
||||
|
||||
__version__ = "1.1.8"
|
||||
__version__ = "1.1.9"
|
||||
|
||||
RASTER_EXT = {".jpg", ".jpeg", ".png", ".webp", ".gif"}
|
||||
VECTOR_EXT = {".svg"}
|
||||
@@ -50,7 +54,7 @@ PNG_TO_JPEG_THRESHOLD_BYTES = 500 * 1024
|
||||
SVG_POLISH_MODULE_NAME = "svg_polish"
|
||||
SVG_PROFILE_BALANCED = "balanced"
|
||||
SVG_PROFILE_AGGRESSIVE = "aggressive"
|
||||
SVG_PROFILE_DEFAULT = SVG_PROFILE_AGGRESSIVE
|
||||
SVG_PROFILE_DEFAULT = SVG_PROFILE_BALANCED
|
||||
|
||||
|
||||
@dataclass
|
||||
@@ -252,17 +256,8 @@ def build_svg_polish_options(svg_polish_module: object, profile: str = SVG_PROFI
|
||||
try:
|
||||
if profile == SVG_PROFILE_BALANCED:
|
||||
return options_type(
|
||||
digits=3,
|
||||
style_to_xml=True,
|
||||
group_collapse=True,
|
||||
simple_colors=True,
|
||||
indent_type="none",
|
||||
newlines=False,
|
||||
strip_xml_prolog=True,
|
||||
strip_comments=True,
|
||||
remove_metadata=True,
|
||||
remove_titles=True,
|
||||
remove_descriptions=True,
|
||||
shorten_ids=True,
|
||||
enable_viewboxing=True,
|
||||
)
|
||||
return options_type(
|
||||
digits=2,
|
||||
@@ -648,6 +643,8 @@ def process_single_deck(
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
update_core_description(work_dir, "PPTX Image Compressor",__version__)
|
||||
|
||||
zip_dir_to_pptx(work_dir, output_pptx)
|
||||
size_after = output_pptx.stat().st_size
|
||||
result.size_after = size_after
|
||||
@@ -845,6 +842,46 @@ def extractParserArguments():
|
||||
|
||||
|
||||
|
||||
def update_core_description(base_dir, app_name, version):
|
||||
core_xml_path = Path(base_dir) / "docProps" / "core.xml"
|
||||
|
||||
if not core_xml_path.exists():
|
||||
raise FileNotFoundError(f"{core_xml_path} nicht gefunden")
|
||||
|
||||
# Namespaces definieren
|
||||
ns = {
|
||||
"cp": "http://schemas.openxmlformats.org/package/2006/metadata/core-properties",
|
||||
"dc": "http://purl.org/dc/elements/1.1/",
|
||||
"dcterms": "http://purl.org/dc/terms/",
|
||||
"xsi": "http://www.w3.org/2001/XMLSchema-instance"
|
||||
}
|
||||
|
||||
# Registrieren, damit Prefixe erhalten bleiben
|
||||
for prefix, uri in ns.items():
|
||||
ET.register_namespace(prefix, uri)
|
||||
|
||||
tree = ET.parse(core_xml_path)
|
||||
root = tree.getroot()
|
||||
|
||||
description_text = f"compressed by {app_name} {version}"
|
||||
|
||||
# Suche vorhandenes Element
|
||||
desc_elem = root.find("dc:description", ns)
|
||||
|
||||
if desc_elem is None:
|
||||
# neu anlegen
|
||||
desc_elem = ET.SubElement(
|
||||
root,
|
||||
f"{{{ns['dc']}}}description"
|
||||
)
|
||||
|
||||
# Text setzen/überschreiben
|
||||
desc_elem.text = description_text
|
||||
|
||||
# Datei speichern
|
||||
tree.write(core_xml_path, encoding="utf-8", xml_declaration=True)
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user