Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
This documentation provides a guide on how to set barcode sizes using in the Aspose.BarCode Cloud SDK for Python. This guide includes examples and descriptions for configuring the height, width, and resolution of barcode images.
The GenerateApi
interface offers several methods for generating barcodes through different types of HTTP requests:
To control the size of a barcode, the following properties in the request objects can be configured:
image_height
: Specifies the height of the barcode image.image_width
: Specifies the width of the barcode image.resolution
: Defines the resolution (DPI) of the barcode image.units
: Defines the measurement units (e.g., pixel, inch, millimeter).import os
from aspose_barcode_cloud import (
ApiClient,
EncodeBarcodeType,
GenerateParams,
BarcodeImageParams,
BarcodeImageFormat,
EncodeData,
EncodeDataType,
Configuration,
)
from aspose_barcode_cloud.api.generate_api import GenerateApi
def make_configuration():
env_token = os.getenv("TEST_CONFIGURATION_ACCESS_TOKEN")
if env_token:
config = Configuration(access_token=env_token)
else:
config = Configuration(
client_id="Client Id from https://dashboard.aspose.cloud/applications",
client_secret="Client Secret from https://dashboard.aspose.cloud/applications",
)
return config
def main():
file_name = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "testdata", "qr.png"))
configuration = make_configuration()
api_client = ApiClient(configuration=configuration)
generate_api = GenerateApi(api_client=api_client)
generator_params = GenerateParams(
EncodeBarcodeType.QR,
EncodeData(EncodeDataType.STRINGDATA, "Aspose.BarCode.Cloud"),
BarcodeImageParams(
BarcodeImageFormat.PNG,
image_height=200,
image_width=200,
resolution=300,
),
)
response = generate_api.generate_body(generator_params)
with open(file_name, "wb") as file:
file.write(response.data)
print(f"File '{file_name}' generated.")
# Run the main function
if __name__ == "__main__":
main()
Result Image is:
import os
from aspose_barcode_cloud import (
ApiClient,
EncodeBarcodeType,
EncodeDataType,
EncodeData,
GenerateParams,
BarcodeImageParams,
BarcodeImageFormat,
GraphicsUnit,
Configuration,
)
from aspose_barcode_cloud.api.generate_api import GenerateApi
def make_configuration():
env_token = os.getenv("TEST_CONFIGURATION_ACCESS_TOKEN")
if env_token:
config = Configuration(access_token=env_token)
else:
config = Configuration(
client_id="Client Id from https://dashboard.aspose.cloud/applications",
client_secret="Client Secret from https://dashboard.aspose.cloud/applications",
)
return config
def main():
# Define the output file path
file_name = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "testdata", "pdf417.png"))
# Create API client and generate parameters
configuration = make_configuration()
api_client = ApiClient(configuration=configuration)
generate_api = GenerateApi(api_client=api_client)
generate_params = GenerateParams(
EncodeBarcodeType.PDF417,
EncodeData(data="Aspose.BarCode.Cloud"),
BarcodeImageParams(
image_format=BarcodeImageFormat.PNG, image_height=2, image_width=3, resolution=96, units=GraphicsUnit.INCH
),
)
# Generate barcode and save to file
response = generate_api.generate_body(generate_params)
with open(file_name, "wb") as file:
file.write(response.data)
print(f"File '{file_name}' generated.")
# Entry point for async execution
if __name__ == "__main__":
main()
Result Image is:
import os
from aspose_barcode_cloud import ApiClient, EncodeBarcodeType, Configuration, GraphicsUnit
from aspose_barcode_cloud.api.generate_api import GenerateApi
def make_configuration():
env_token = os.getenv("TEST_CONFIGURATION_ACCESS_TOKEN")
if env_token:
config = Configuration(access_token=env_token)
else:
config = Configuration(
client_id="Client Id from https://dashboard.aspose.cloud/applications",
client_secret="Client Secret from https://dashboard.aspose.cloud/applications",
)
return config
def main():
config = make_configuration()
api_client = ApiClient(configuration=config)
api = GenerateApi(api_client=api_client)
file_name = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "testdata", "aztec.png"))
response = api.generate_multipart(
barcode_type=EncodeBarcodeType.AZTEC,
data="Aspose.BarCode.Cloud",
image_height=200,
image_width=200,
resolution=150,
units=GraphicsUnit.POINT,
)
with open(file_name, "wb") as file_stream:
file_stream.write(response.data)
print(f"File '{file_name}' generated.")
if __name__ == "__main__":
main()
Result Image is:
Setting the correct barcode dimensions ensures optimal readability and compatibility with various scanning devices. With Aspose.BarCode Cloud SDK for Python, you can customize the barcode’s height, width, and resolution to meet specific requirements, whether for product labeling, logistics, or QR code marketing.
Proper barcode sizing improves scanning accuracy and ensures a better user experience. By setting the right dimensions using Aspose.BarCode Cloud SDK for Python, you can ensure your barcodes are perfectly tailored for their intended use.
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.