השתמש ב-Python עבור התאמת תמונות ב-PNG
צור אפליקציות Python כדי להתאים תמונות ותמונות PNG באמצעות ממשקי API של שרת
כיצד להתאים תמונות ותמונות PNG עם Python
בזמן צילום תמונות, עלולות להתרחש טעויות עקב הגדרות שגויות של המצלמה. תאורה לא מבוקרת יכולה גם להשפיע על התוצאות, ואפילו צילומים מקצועיים עשויים להפגין פגמים. עם זאת, בתרחישים כאלה, קיימת שיטה לשפר את התמונה על ידי שימוש בכלי תוכנה המסופקים על ידי ספריית Python. יש לך את היכולת לכוונן עדין את הבהירות, הניגודיות ואיזון הצבעים של התמונה. לדוגמה, אם תמונה נראית עמומה מדי, הגברת הבהירות תאיר אזורים כהים יותר, ותחשוף פרטים שבעבר הוסתרו בצללים. אם התמונה שלך מציגה יריעות צבע לא רצויות עקב תאורה מלאכותית, תוכל לתקן זאת באמצעות תכונת התאמת גמא הצבע. כדי לבצע שינויים אלה בקבצים PNG, אתה יכול להשתמש בהם Aspose.Imaging for Python דרך NET API שהוא עשיר בתכונות, חזק וקל לשימוש למניפולציה והמרה של תמונות API עבור פלטפורמת Python. אתה יכול להתקין אותו באמצעות הפקודה הבאה מפקודת המערכת שלך.
שורת הפקודה של המערכת
>> pip install aspose-imaging-python-net
שלבים לכוונון PNG באמצעות Python
אתה צריך את aspose-imaging-python-net כדי לנסות את זרימת העבודה הבאה בסביבה שלך.
- טען קבצים PNG בשיטת Image.Load
- התאם תמונות;
- שמור תמונה דחוסה לדיסק בפורמט הנתמך על ידי Aspose.Imaging
דרישות מערכת
Aspose.Imaging עבור Python נתמך בכל מערכות ההפעלה העיקריות. רק ודא שיש לך את התנאים המוקדמים הבאים.
- Microsoft Windows / Linux עם .NET Core Runtime.
- מנהל חבילות Python ו- PyPi.
התאם תמונות PNG - Python
from aspose.imaging import * | |
from aspose.imaging.fileformats.bmp import * | |
from aspose.imaging.fileformats.dicom import * | |
from aspose.imaging.fileformats.emf import * | |
from aspose.imaging.fileformats.jpeg import * | |
from aspose.imaging.fileformats.jpeg2000 import * | |
from aspose.imaging.fileformats.png import * | |
from aspose.imaging.fileformats.psd import * | |
from aspose.imaging.fileformats.tiff.enums import * | |
from aspose.imaging.imagefilters.filteroptions import * | |
from aspose.imaging.imageoptions import * | |
from aspose.imaging.masking import * | |
from aspose.imaging.masking.options import * | |
from aspose.imaging.masking.result import * | |
from aspose.imaging.sources 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 adjust_gamma_rgb(): | |
# https://apireference.aspose.com/imaging/python-net/aspose.imaging.rasterimage/adjustgamma | |
filter_images(lambda image: image.adjust_gamma(5, 0.1, 0.1), "adjustgammargb") | |
def adjust_gamma(): | |
filter_images(lambda image: image.adjust_gamma(3), "adjustgamma") | |
def adjust_contrast(): | |
filter_images(lambda image: image.adjust_contrast(50), "adjustcontrast") | |
def adjust_brightness(): | |
filter_images(lambda image: image.adjust_brightness(100), "adjustbrightness") | |
def filter_images(do_filter, filter_name): | |
obj_init = [] | |
obj_init.append("jpg") | |
obj_init.append("png") | |
obj_init.append("bmp") | |
obj_init.append("apng") | |
obj_init.append("dicom") | |
obj_init.append("jp2") | |
obj_init.append("j2k") | |
obj_init.append("tga") | |
obj_init.append("webp") | |
obj_init.append("tif") | |
obj_init.append("gif") | |
obj_init.append("ico") | |
raster_formats = obj_init | |
obj_init2 = [] | |
obj_init2.append("svg") | |
obj_init2.append("otg") | |
obj_init2.append("odg") | |
obj_init2.append("eps") | |
obj_init2.append("wmf") | |
obj_init2.append("emf") | |
obj_init2.append("wmz") | |
obj_init2.append("emz") | |
obj_init2.append("cmx") | |
obj_init2.append("cdr") | |
vector_formats = obj_init2 | |
all_formats = [] | |
all_formats.extend(raster_formats) | |
all_formats.extend(vector_formats) | |
for format_ext in all_formats: | |
input_file = os.path.join(templates_folder, f"template.{format_ext}") | |
if not os.path.exists(input_file): | |
continue | |
is_vector_format = format_ext in vector_formats | |
if is_vector_format: | |
input_file = rasterize_vector_image(format_ext, input_file) | |
output_file = os.path.join(templates_folder, f"{filter_name}_{format_ext}.png") | |
print(format_ext) | |
# explicit type casting from Image to RasterImage | |
with as_of(Image.load(input_file), RasterImage) as image: | |
do_filter(image) | |
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 | |
page_index = 0 | |
for page in multi_page.pages: | |
file_name = f"{filter_name}_page{page_index}_{format_ext}.png" | |
page.save(os.path.join(templates_folder + file_name), PngOptions()) | |
# delete an output file | |
delete_file(os.path.join(templates_folder + file_name)) | |
page_index += 1 | |
else: | |
image.save(output_file, PngOptions()) | |
# delete an output file | |
delete_file(output_file) | |
# delete a rasterized file | |
if is_vector_format: | |
delete_file(input_file) | |
def delete_file(file): | |
if delete_output: | |
os.remove(file) | |
def rasterize_vector_image(format_ext, input_file): | |
output_file = os.path.join(templates_folder, f"rasterized.{format_ext}.png") | |
with Image.load(input_file) as image: | |
image.save(output_file, PngOptions()) | |
return output_file | |
# call one of the functions | |
adjust_brightness() | |
#adjust_contrast() | |
#adjust_gamma() | |
#adjust_gamma_rgb() |
אודות Aspose.Imaging עבור API של Python
Aspose.Imaging API הוא פתרון לעיבוד תמונה ליצירה, שינוי, ציור או המרת תמונות (תמונות) בתוך יישומים. הוא מציע: עיבוד תמונה חוצה פלטפורמות, כולל אך לא רק המרות בין פורמטים שונים של תמונה (כולל עיבוד תמונה אחיד מרובה עמודים או ריבוי מסגרות), שינויים כגון ציור, עבודה עם פרימיטיבים גרפיים, טרנספורמציות (שינוי גודל, חיתוך, הפוך וסיבוב , בינאריזציה, גווני אפור, התאמה), תכונות מתקדמות של מניפולציה של תמונות (סינון, שיטוט, מיסוך, ביטול הטיה) ואסטרטגיות אופטימיזציה של זיכרון. זוהי ספרייה עצמאית ואינה תלויה בתוכנה כלשהי לפעולות תמונה. אפשר להוסיף בקלות תכונות המרת תמונה בעלות ביצועים גבוהים עם ממשקי API מקוריים בתוך פרויקטים. אלו הם 100% ממשקי API פרטיים מקומיים ותמונות מעובדות בשרתים שלך.התאם את PNG באמצעות אפליקציה מקוונת
התאם את המסמכים של PNG על ידי ביקור ב אתר האינטרנט של הדגמות חיות . להדגמה החיה יש את היתרונות הבאים
PNG מה זה PNG פורמט קובץ
PNG, Portable Network Graphics, מתייחס לסוג של פורמט קובץ תמונת רסטר המשתמש בדחיסה ללא הפסדים. פורמט קובץ זה נוצר כתחליף ל-Graphics Interchange Format (GIF) ואין לו מגבלות זכויות יוצרים. עם זאת, פורמט קובץ PNG אינו תומך בהנפשות. פורמט קובץ PNG תומך בדחיסת תמונה ללא הפסדים שהופך אותו לפופולרי בקרב המשתמשים שלו. עם חלוף הזמן, PNG התפתח כאחד מפורמטי קבצי התמונה הנפוצים ביותר. כמעט לכל מערכות ההפעלה יש תמיכה בפתיחת קבצי PNG. לדוגמה, ל-Microsoft Windows Viewer יש את היכולת לפתוח קבצי PNG מכיוון שלמערכת ההפעלה יש כברירת מחדל את התמיכה הזמינה כחלק מההתקנה.
קרא עודתבניות התאמה נתמכות אחרות
באמצעות Python, אפשר להתאים בקלות פורמטים שונים כולל.