השתמש ב-Python עבור דחיסת תמונות CMX
צור אפליקציות Python כדי לדחוס תמונות ותמונות CMX באמצעות ממשקי API של שרת
כיצד לדחוס תמונות ותמונות CMX עם Python
התאמת תמונות לפרסום כוללת לא רק תהליכי יצירה אלא גם התאמות טכניות, כמו דחיסת קבצים. בדרך כלל, תמונות ברזולוציה גבוהה נחוצות עבור חומרים מודפסים או פרסום חוצות, בעוד שאתרים עשויים להתמודד עם אתגרים עם גדלי קבצים גדולים. הגדרות דחיסת התמונה עשויות להשתנות בהתאם לשימוש המיועד והמקום שבו הן יפורסמו. הורדת קבצים גדולים עשויה להימשך זמן רב להורדה, במיוחד בחיבורים ניידים, ומשפיעים על חווית המשתמש הכוללת. עם זאת, תמונות דחוסות מדי עלולות לסבול מטשטוש ומפיקסלציה גלויה, ולערער את האיכות החזותית. השגת איזון בין גודל הקובץ ואיכות התמונה דורשת בחירה קפדנית של אלגוריתמים ורמות דחיסה. כדי לדחוס תמונות בפורמט CMX, נשתמש Aspose.Imaging for Python דרך NET API שהוא עשיר בתכונות, חזק וקל לשימוש למניפולציה והמרה של תמונות API עבור פלטפורמת Python. אתה יכול להתקין אותו באמצעות הפקודה הבאה מפקודת המערכת שלך.
שורת הפקודה של המערכת
>> pip install aspose-imaging-python-net
שלבים לדחיסת CMXs באמצעות Python
אתה צריך את aspose-imaging-python-net כדי לנסות את זרימת העבודה הבאה בסביבה שלך.
- טען קבצים CMX בשיטת Image.Load
- דחוס תמונות;
- שמור תמונה דחוסה לדיסק בפורמט הנתמך על ידי Aspose.Imaging
דרישות מערכת
Aspose.Imaging עבור Python נתמך בכל מערכות ההפעלה העיקריות. רק ודא שיש לך את התנאים המוקדמים הבאים.
- Microsoft Windows / Linux עם .NET Core Runtime.
- מנהל חבילות Python ו- PyPi.
דחוס תמונות CMX - Python
from aspose.imaging.imageoptions import * | |
from aspose.imaging import * | |
from aspose.pycore import as_of, is_assignable | |
import os | |
if 'TEMPLATE_DIR' in os.environ: | |
templates_folder = os.environ['TEMPLATE_DIR'] | |
else: | |
templates_folder = r"C:\Users\USER\Downloads\templates" | |
delete_output = 'SAVE_OUTPUT' not in os.environ | |
def compress_vector_format_to_svg(): | |
obj_init = [] | |
obj_init.append("cdr") | |
obj_init.append("cmx") | |
obj_init.append("odg") | |
obj_init.append("otg") | |
obj_init.append("eps") | |
format_exts = obj_init | |
for format_ext in format_exts: | |
input_file = os.path.join(templates_folder, f"template.{format_ext}") | |
output_file = os.path.join(templates_folder, f"compressed_{format_ext.upper()}") | |
with Image.load(input_file) as image: | |
def rasterization_options_factory(): | |
tmp_switch = image.file_format | |
if tmp_switch == FileFormat.CDR: | |
obj_init2 = CdrRasterizationOptions() | |
obj_init2.page_width = float(image.width) | |
obj_init2.page_height = float(image.height) | |
return obj_init2 | |
elif tmp_switch == FileFormat.CMX: | |
obj_init3 = CmxRasterizationOptions() | |
obj_init3.page_width = float(image.width) | |
obj_init3.page_height = float(image.height) | |
return obj_init3 | |
elif tmp_switch == FileFormat.ODG: | |
obj_init4 = OdgRasterizationOptions() | |
obj_init4.page_width = float(image.width) | |
obj_init4.page_height = float(image.height) | |
return obj_init4 | |
elif tmp_switch == FileFormat.OTG: | |
obj_init5 = OtgRasterizationOptions() | |
obj_init5.page_width = float(image.width) | |
obj_init5.page_height = float(image.height) | |
return obj_init5 | |
else: | |
return None | |
multi_page = None | |
# if image implements an IMultipageImage interface | |
if is_assignable(image, IMultipageImage): | |
multi_page = as_of(image, IMultipageImage) | |
if multi_page is not None and multi_page.page_count > 1: | |
# for loop | |
for_first_step2 = True | |
page_index = 0 | |
for page in multi_page.pages: | |
obj_init6 = SvgOptions() | |
obj_init6.compress = True | |
obj_init6.vector_rasterization_options = rasterization_options_factory() | |
out_file = f"{output_file}_p{page_index + 1}.svgz" | |
page.save(out_file, obj_init6) | |
if delete_output: | |
os.remove(out_file) | |
page_index += 1 | |
else: | |
obj_init7 = SvgOptions() | |
obj_init7.compress = True | |
obj_init7.vector_rasterization_options = rasterization_options_factory() | |
image.save(output_file + ".svgz", obj_init7) | |
if delete_output: | |
os.remove(output_file + ".svgz") | |
def compress_vector_format_to_wmf(): | |
obj_init8 = [] | |
obj_init8.append("cdr") | |
obj_init8.append("cmx") | |
obj_init8.append("odg") | |
obj_init8.append("otg") | |
obj_init8.append("eps") | |
format_exts = obj_init8 | |
for format_ext in format_exts: | |
input_file = os.path.join(templates_folder, f"template.{format_ext}") | |
output_file = os.path.join(templates_folder, f"compressed_{format_ext.upper()}") | |
with Image.load(input_file) as image: | |
def rasterization_options_factory(): | |
tmp_switch = image.file_format | |
if tmp_switch == FileFormat.CDR: | |
obj_init9 = CdrRasterizationOptions() | |
obj_init9.page_width = float(image.width) | |
obj_init9.page_height = float(image.height) | |
return obj_init9 | |
elif tmp_switch == FileFormat.CMX: | |
obj_init10 = CmxRasterizationOptions() | |
obj_init10.page_width = float(image.width) | |
obj_init10.page_height = float(image.height) | |
return obj_init10 | |
elif tmp_switch == FileFormat.ODG: | |
obj_init11 = OdgRasterizationOptions() | |
obj_init11.page_width = float(image.width) | |
obj_init11.page_height = float(image.height) | |
return obj_init11 | |
elif tmp_switch == FileFormat.OTG: | |
obj_init12 = OtgRasterizationOptions() | |
obj_init12.page_width = float(image.width) | |
obj_init12.page_height = float(image.height) | |
return obj_init12 | |
else: | |
return None | |
multi_page = None | |
# if image implements an IMultipageImage interface | |
if is_assignable(image, IMultipageImage): | |
multi_page = as_of(image, IMultipageImage) | |
if multi_page is not None and multi_page.page_count > 1: | |
# for loop | |
for_first_step2 = True | |
page_index = 0 | |
for page in multi_page.pages: | |
obj_init13 = WmfOptions() | |
obj_init13.compress = True | |
obj_init13.vector_rasterization_options = rasterization_options_factory() | |
out_file = f"{output_file}_p{page_index + 1}.wmz" | |
page.save(out_file, obj_init13) | |
if delete_output: | |
os.remove(out_file) | |
else: | |
obj_init14 = WmfOptions() | |
obj_init14.compress = True | |
obj_init14.vector_rasterization_options = rasterization_options_factory() | |
image.save(output_file + ".wmz", obj_init14) | |
if delete_output: | |
os.remove(output_file + ".wmz") | |
def compress_vector_formats_to_emf(): | |
obj_init15 = [] | |
obj_init15.append("cdr") | |
obj_init15.append("cmx") | |
obj_init15.append("odg") | |
obj_init15.append("otg") | |
obj_init15.append("eps") | |
format_exts = obj_init15 | |
for format_ext in format_exts: | |
input_file = os.path.join(templates_folder, f"template.{format_ext}") | |
output_file = os.path.join(templates_folder, f"compressed_{format_ext.upper()}") | |
with Image.load(input_file) as image: | |
def rasterization_options_factory(): | |
tmp_switch = image.file_format | |
if tmp_switch == FileFormat.CDR: | |
obj_init16 = CdrRasterizationOptions() | |
obj_init16.page_width = float(image.width) | |
obj_init16.page_height = float(image.height) | |
return obj_init16 | |
elif tmp_switch == FileFormat.CMX: | |
obj_init17 = CmxRasterizationOptions() | |
obj_init17.page_width = float(image.width) | |
obj_init17.page_height = float(image.height) | |
return obj_init17 | |
elif tmp_switch == FileFormat.ODG: | |
obj_init18 = OdgRasterizationOptions() | |
obj_init18.page_width = float(image.width) | |
obj_init18.page_height = float(image.height) | |
return obj_init18 | |
elif tmp_switch == FileFormat.OTG: | |
obj_init19 = OtgRasterizationOptions() | |
obj_init19.page_width = float(image.width) | |
obj_init19.page_height = float(image.height) | |
return obj_init19 | |
else: | |
return None | |
multi_page = None | |
# if image implements an IMultipageImage interface | |
if is_assignable(image, IMultipageImage): | |
multi_page = as_of(image, IMultipageImage) | |
if multi_page is not None and multi_page.page_count > 1: | |
# for loop | |
for_first_step2 = True | |
page_index = 0 | |
for page in multi_page.pages: | |
obj_init20 = EmfOptions() | |
obj_init20.compress = True | |
obj_init20.vector_rasterization_options = rasterization_options_factory() | |
out_file = f"{output_file}_p{page_index + 1}.emz" | |
page.save(out_file, obj_init20) | |
if delete_output: | |
os.remove(out_file) | |
else: | |
obj_init21 = EmfOptions() | |
obj_init21.compress = True | |
obj_init21.vector_rasterization_options = rasterization_options_factory() | |
image.save(output_file + ".emz", obj_init21) | |
if delete_output: | |
os.remove(output_file + ".emz") | |
# run | |
compress_vector_formats_to_emf() | |
compress_vector_format_to_svg() | |
compress_vector_format_to_wmf() |
אודות Aspose.Imaging עבור API של Python
Aspose.Imaging API הוא פתרון לעיבוד תמונה ליצירה, שינוי, ציור או המרת תמונות (תמונות) בתוך יישומים. הוא מציע: עיבוד תמונה חוצה פלטפורמות, כולל אך לא רק המרות בין פורמטים שונים של תמונה (כולל עיבוד תמונה אחיד מרובה עמודים או ריבוי מסגרות), שינויים כגון ציור, עבודה עם פרימיטיבים גרפיים, טרנספורמציות (שינוי גודל, חיתוך, הפוך וסיבוב , בינאריזציה, גווני אפור, התאמה), תכונות מתקדמות של מניפולציה של תמונות (סינון, שיטוט, מיסוך, ביטול הטיה) ואסטרטגיות אופטימיזציה של זיכרון. זוהי ספרייה עצמאית ואינה תלויה בתוכנה כלשהי לפעולות תמונה. אפשר להוסיף בקלות תכונות המרת תמונה בעלות ביצועים גבוהים עם ממשקי API מקוריים בתוך פרויקטים. אלו הם 100% ממשקי API פרטיים מקומיים ותמונות מעובדות בשרתים שלך.דחוס CMX באמצעות אפליקציה מקוונת
דחוס מסמכים ב-CMX על ידי ביקור ב אתר האינטרנט של הדגמות חיות . להדגמה החיה יש את היתרונות הבאים
CMX מה זה CMX פורמט קובץ
קבצים עם סיומת CMX הם פורמט קובץ תמונה של Corel Exchange המשמש כמצגת על ידי יישומי CorelSuite. הוא מכיל נתוני תמונה כגרפיקה וקטורית וכן מטא נתונים המתארים את התמונה. ניתן לפתוח קבצי CMX על ידי CorelDraw, Corel Presentations, Paint Shop Pro וגרסאות מסוימות של Adobe Illustrator.
קרא עודפורמטי דחיסה נתמכים אחרים
באמצעות Python, אפשר לדחוס בקלות פורמטים שונים כולל.