ใช้ Python สำหรับการปรับรูปภาพ ODG
สร้างแอป Python เพื่อปรับ ODG รูปภาพและรูปภาพผ่าน Server API
วิธีปรับ ODG รูปภาพและภาพถ่ายด้วย Python
ขณะถ่ายภาพ ข้อผิดพลาดอาจเกิดขึ้นได้เนื่องจากการตั้งค่ากล้องไม่ถูกต้อง แสงที่ไม่สามารถควบคุมได้ยังส่งผลต่อผลลัพธ์ และแม้แต่ภาพถ่ายระดับมืออาชีพก็อาจมีข้อบกพร่องได้ อย่างไรก็ตาม ในสถานการณ์ดังกล่าว มีวิธีการปรับปรุงรูปภาพโดยใช้เครื่องมือซอฟต์แวร์ที่มาจากไลบรารี Python คุณมีความสามารถในการปรับแต่งความสว่าง คอนทราสต์ และความสมดุลของสีของภาพได้อย่างละเอียด ตัวอย่างเช่น หากภาพถ่ายดูสลัวเกินไป การเพิ่มความสว่างจะทำให้บริเวณที่มืดสว่างขึ้น ซึ่งเผยให้เห็นรายละเอียดที่แต่ก่อนถูกบดบังด้วยเงามืด หากรูปภาพของคุณแสดงสีที่ไม่พึงประสงค์เนื่องจากแสงประดิษฐ์ คุณสามารถแก้ไขปัญหานี้ได้โดยใช้คุณสมบัติการปรับแกมมาสี หากต้องการดำเนินการแก้ไขเหล่านี้กับไฟล์ ODG คุณสามารถใช้ประโยชน์จาก Aspose.Imaging สำหรับ Python ผ่าน .NET API ซึ่งเป็น API การจัดการรูปภาพและการแปลงที่มีคุณลักษณะหลากหลาย ทรงพลัง และใช้งานง่ายสำหรับแพลตฟอร์ม Python คุณสามารถติดตั้งได้โดยใช้คำสั่งต่อไปนี้จากคำสั่งระบบของคุณ
บรรทัดคำสั่งของระบบ
>> pip install aspose-imaging-python-net
ขั้นตอนในการปรับ ODGs ผ่าน Python
คุณต้องใช้ aspose-imaging-python-net เพื่อลองใช้เวิร์กโฟลว์ต่อไปนี้ในสภาพแวดล้อมของคุณเอง
- โหลดไฟล์ ODG ด้วยวิธี Image.Load
- ปรับภาพ;
- บันทึกภาพที่บีบอัดลงในแผ่นดิสก์ในรูปแบบที่รองรับโดย Aspose.Imaging
ความต้องการของระบบ
Aspose.Imaging สำหรับ Python ได้รับการสนับสนุนในระบบปฏิบัติการหลักทั้งหมด เพียงตรวจสอบให้แน่ใจว่าคุณมีข้อกำหนดเบื้องต้นดังต่อไปนี้
- Microsoft Windows / Linux พร้อม .NET Core Runtime
- ตัวจัดการแพ็คเกจ Python และ PyPi
ปรับภาพ ODG - 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 สำหรับ Python API
Aspose.Imaging API เป็นโซลูชันการประมวลผลรูปภาพเพื่อสร้าง แก้ไข วาดหรือแปลงรูปภาพ (ภาพถ่าย) ภายในแอปพลิเคชัน นำเสนอ: การประมวลผลภาพข้ามแพลตฟอร์ม รวมถึงแต่ไม่จำกัดเพียงการแปลงระหว่างรูปแบบภาพต่างๆ (รวมถึงการประมวลผลภาพแบบหลายหน้าหรือหลายเฟรมแบบเดียวกัน) การปรับเปลี่ยน เช่น การวาด การทำงานกับภาพกราฟิกดั้งเดิม การแปลงภาพ (ปรับขนาด ครอบตัด พลิกและหมุน , ไบนารี, ระดับสีเทา, ปรับ), คุณสมบัติการจัดการภาพขั้นสูง (การกรอง, การแยกสี, การปิดบัง, การเดสก์) และกลยุทธ์การปรับหน่วยความจำให้เหมาะสม เป็นไลบรารีแบบสแตนด์อโลนและไม่ขึ้นกับซอฟต์แวร์ใด ๆ สำหรับการทำงานของรูปภาพ คุณสามารถเพิ่มคุณสมบัติการแปลงรูปภาพประสิทธิภาพสูงด้วย API ดั้งเดิมภายในโปรเจ็กต์ได้อย่างง่ายดาย สิ่งเหล่านี้เป็น API ภายในองค์กรที่เป็นส่วนตัว 100% และอิมเมจได้รับการประมวลผลที่เซิร์ฟเวอร์ของคุณปรับ ODG ผ่านแอปออนไลน์
ปรับเอกสาร ODG โดยไปที่ เว็บไซต์สาธิตสด การสาธิตสดมีประโยชน์ดังต่อไปนี้
ODG คืออะไร ODG รูปแบบไฟล์
รูปแบบไฟล์ ODG ถูกใช้โดยแอปพลิเคชัน Draw ของ Apache OpenOffice เพื่อจัดเก็บองค์ประกอบการวาดเป็นภาพเวกเตอร์ เป็นไปตามข้อกำหนดรูปแบบไฟล์ XML ที่ร่างโดย Advancement of Structural Information Standards (OASIS) ODG แสดงภาพวาดเป็นภาพเวกเตอร์โดยใช้จุด เส้น และเส้นโค้ง นอกจาก OpenOffice แล้ว LibreOffice และแอปพลิเคชั่นอื่น ๆ ยังรองรับการทำงานกับรูปแบบไฟล์ ODG รูปแบบอื่นๆ ที่ OpenOffice รองรับ เช่น ODT, ODF, ODP และ ODS
อ่านเพิ่มเติมรูปแบบการปรับอื่น ๆ ที่รองรับ
ด้วยการใช้ Python เราสามารถปรับรูปแบบต่างๆ ได้อย่างง่ายดายรวมถึง