แม้แต่การแก้ไขรูปภาพที่เร็วที่สุดก็อาจใช้เวลามากเกินไปในการดำเนินการให้เสร็จสิ้น และการปรับขนาดรูปภาพก็เป็นหนึ่งในงานที่น่ารำคาญอย่างแน่นอน ด้วย Cloudmersive Image API คุณสามารถตัดขั้นตอนบางอย่างออกจากกระบวนการดังกล่าว และเปิดใช้งานแอปพลิเคชันของคุณเพื่อปรับขนาดรูปภาพโดยอัตโนมัติตามพารามิเตอร์ความกว้างและความสูงที่ระบุ ซึ่งจะทำให้ขั้นตอนการแก้ไขตามปกติของรูปภาพที่ต้องการขนาดเฉพาะสำหรับบริบทเฉพาะเจาะจงสั้นลงได้อย่างมาก (เช่น เพื่อให้พอดีกับตำแหน่งที่ถูกต้องบนหน้าเว็บ) ด้านล่างนี้ เมื่อใช้โค้ดโดยตรงจาก Cloudmersive API Console ฉันจะแนะนำวิธีเชื่อมต่อกับ API นี้ใน Python

ในการเริ่มต้น ให้รันคำสั่งด้านล่าง (ซึ่งจะติดตั้ง Python SDK):

pip install cloudmersive-image-api-client

หลังจากนั้น ใช้ตัวอย่างด้านล่างเพื่อเริ่มฟังก์ชันเรียกกลับ & ตรวจสอบสิทธิ์คีย์ Cloudmersive API ของคุณ:

from __future__ import print_function
import time
import cloudmersive_image_api_client
from cloudmersive_image_api_client.rest import ApiException
from pprint import pprint
# Configure API key authorization: Apikey
configuration = cloudmersive_image_api_client.Configuration()
configuration.api_key['Apikey'] = 'YOUR_API_KEY'

สุดท้าย คุณสามารถสรุปฟังก์ชันด้วยโค้ดที่เหลือด้านล่างได้ ในขั้นตอนนี้ ตรวจสอบให้แน่ใจว่าได้ระบุขนาดของภาพถ่ายของคุณตามที่ระบุไว้ในเอกสารประกอบ:

# create an instance of the API class
api_instance = cloudmersive_image_api_client.ResizeApi(cloudmersive_image_api_client.ApiClient(configuration))
width = 56 # int | Width of the output image - final image will be exactly this width
height = 56 # int | Height of the output image - final image will be exactly this height
image_file = '/path/to/inputfile' # file | Image file to perform the operation on.  Common file formats such as PNG, JPEG are supported.
try:
    # Resize an image
    api_response = api_instance.resize_resize_simple(width, height, image_file)
    pprint(api_response)
except ApiException as e:
    print("Exception when calling ResizeApi->resize_resize_simple: %s\n" % e)