CDR 이미지 압축에는 Python 사용
서버 API를 통해 CDR 이미지와 사진을 압축하는 Python 앱 만들기
Python를 사용하여 CDR 이미지와 사진을 압축하는 방법
출판을 위한 이미지 조정에는 창의적인 프로세스뿐만 아니라 파일 압축과 같은 기술적 조정도 포함됩니다. 일반적으로 인쇄물이나 옥외 광고에는 고해상도 이미지가 필요한 반면, 웹사이트는 파일 크기가 커서 문제가 발생할 수 있습니다. 이미지 압축 설정은 용도와 게시 위치에 따라 달라질 수 있습니다. 대용량 파일은 다운로드하는 데 상당한 시간이 걸릴 수 있으며, 특히 모바일 연결에서는 전반적인 사용자 경험에 영향을 미칠 수 있습니다. 그러나 지나치게 압축된 이미지는 흐려지고 눈에 보이는 픽셀화로 인해 시각적 품질이 저하될 수 있습니다. 파일 크기와 이미지 품질 사이의 균형을 이루려면 알고리즘과 압축 수준을 신중하게 선택해야 합니다. CDR 형식으로 이미지를 압축하기 위해 다음을 사용합니다. Aspose.Imaging for Python via .NET API는 기능이 풍부하고 강력하며 사용하기 쉬운 Python 플랫폼용 이미지 조작 및 변환 API입니다. 시스템 명령에서 다음 명령을 사용하여 설치할 수 있습니다.
시스템 명령줄
>> pip install aspose-imaging-python-net
Python를 통해 CDR을 압축하는 단계
자신의 환경에서 다음 워크플로를 시도하려면 aspose-imaging-python-net 이 필요합니다.
- Image.Load 메서드로 CDR 파일 로드
- 이미지 압축
- Aspose.Imaging 형식에서 지원하는 압축 이미지를 디스크에 저장
시스템 요구 사항
Python용 Aspose.Imaging은 모든 주요 운영 체제에서 지원됩니다. 다음 전제 조건이 있는지 확인하십시오.
- .NET Core 런타임이 포함된 Microsoft Windows/Linux.
- Python 및 PyPi 패키지 관리자.
CDR 이미지 압축 - 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() |
Python API용 Aspose.Imaging 정보
Aspose.Imaging API는 애플리케이션 내에서 이미지(사진)를 생성, 수정, 그리기 또는 변환하는 이미지 처리 솔루션입니다. 다양한 이미지 형식 간의 변환(균일한 다중 페이지 또는 다중 프레임 이미지 처리 포함), 그리기와 같은 수정, 그래픽 프리미티브 작업, 변환(크기 조정, 자르기, 뒤집기 및 회전)을 포함하되 이에 국한되지 않는 플랫폼 간 이미지 처리 , 이진화, 회색조, 조정), 고급 이미지 조작 기능(필터링, 디더링, 마스킹, 기울기 보정) 및 메모리 최적화 전략. 독립 실행형 라이브러리이며 이미지 작업을 위해 소프트웨어에 의존하지 않습니다. 프로젝트 내에서 기본 API를 사용하여 고성능 이미지 변환 기능을 쉽게 추가할 수 있습니다. 이는 100% 비공개 온프레미스 API이며 이미지는 서버에서 처리됩니다.온라인 앱을 통해 CDR 압축
라이브 데모 웹사이트 를 방문하여 CDR 문서를 압축합니다. 라이브 데모에는 다음과 같은 이점이 있습니다.
CDR 뭐가 CDR 파일 형식
CDR 파일은 인코딩 및 압축된 디지털 이미지를 저장하기 위해 CorelDRAW로 기본 생성되는 벡터 드로잉 이미지 파일입니다. 이러한 도면 파일에는 이미지 내용의 벡터 표현을 위한 텍스트, 선, 모양, 이미지, 색상 및 효과가 포함됩니다. CDR 파일은 CorelDRAW를 기본 응용 프로그램으로 사용하여 열 수 있으며 PDF, JPG, PNG, BMP 및 AI와 같은 다른 형식으로 변환할 수도 있습니다. 브로셔, 타블로이드, 봉투, 엽서 등 다양한 그래픽 데이터의 표현에 사용할 수 있습니다. CorelDRAW 외에도 Corel Paintshop Pro 및 CorelDRAW Graphics 제품군과 같은 다른 Corel 제품도 CDR 파일 형식을 열 수 있습니다.
더 읽어보기기타 지원되는 압축 형식
Python을 사용하면 다음을 포함한 다양한 형식을 쉽게 압축할 수 있습니다.