Skip to content

Instantly share code, notes, and snippets.

@aspose-imaging-cloud-examples
Last active May 24, 2022 09:37

Aspose.Imaging.Cloud PHP API allows programmatically convert your png images to various image formats with high quality in your PHP application or Web service.

You can:

  • convert png to file;
  • convert png to stream;

Interested ?

You may go further at : https://products.aspose.cloud/imaging/php/

use Aspose\Imaging\Configuration;
use Aspose\Imaging\ImagingApi;
use Aspose\Imaging\Model\Requests\ConvertImageRequest;
use Aspose\Imaging\Model\Requests\CreateConvertedImageRequest;
use Exception;
// Get ClientId and ClientSecret from https://dashboard.aspose.cloud/
// or use on-premise version (https://docs.aspose.cloud/imaging/getting-started/how-to-run-docker-container/)
$ImageFileName = "example_image.png";
$ImagesFolder = "ExampleImages";
$CloudFolder = "CloudImages";
$OutputFolder = "Output";
$clientSecret = null;
$clientId = null;
$baseUrl = "https://api.aspose.cloud";
$imagingConfig = new Configuration();
$imagingConfig->setClientSecret($clientSecret);
$imagingConfig->setClientId($clientId);
$imagingConfig->setBaseUrl($baseUrl);
$imagingApi = new ImagingApi($imagingConfig);
/**
* Export an image to another format.
*/
public function ConvertImageFromStorage()
{
$this->UploadSampleImageToCloud();
$inputImage = file_get_contents($this->ImagesFolder . DIRECTORY_SEPARATOR . $this->ImageFileName);
$request = new UploadFileRequest($this->CloudPath . DIRECTORY_SEPARATOR . $this->ImageName, $inputImage);
$response = self::$imagingApi->uploadFile($request);
if ($response->getErrors() != null && count($response->getErrors()) == 0)
echo ("Uploading errors count: " . count($response->getErrors()));
// Please refer to https://docs.aspose.cloud/imaging/supported-file-formats/#convert
// for possible output formats
$format = "apng";
$folder = $this->CloudFolder; // Input file is saved at the desired folder in the storage
$storage = null; // Cloud Storage name
$request = new ConvertImageRequest($this->ImageFileName, $format, $folder, $storage);
$convertedImage = self::$imagingApi->convertImage($request);
// Save the image file to output folder
$convertedImageName = substr($this->ImageFileName, 0, strrpos($this->ImageFileName, ".") + 1) . "apng";
$path = $this-> OutputFolder . DIRECTORY_SEPARATOR . $convertedImageName;
file_put_contents($path, $convertedImage);
}
/**
* Convert an image to another format. Image data is passed in a request stream.
*/
public function CreateConvertedImageFromRequest()
{
// Please refer to https://docs.aspose.cloud/imaging/supported-file-formats/#convert
// for possible output formats
$format = "apng";
$outPath = null; // Path to updated file (if this is empty, response contains streamed image)
$storage = null; // Cloud Storage name
$inputStream = file_get_contents($this->ImagesFolder . DIRECTORY_SEPARATOR . $this->ImageFileName);
$request = new CreateConvertedImageRequest($inputStream, $format, $outPath, $storage);
$convertdImage = self::$imagingApi->createConvertedImage($request);
// Save the image file to output folder
$convertedImageName = substr($this->ImageFileName, 0, strrpos($this->ImageFileName, ".") + 1) . "apng";
$path = $this-> OutputFolder . DIRECTORY_SEPARATOR . $convertedImageName;
file_put_contents($path, $convertedImage);
}
use Aspose\Imaging\Configuration;
use Aspose\Imaging\ImagingApi;
use Aspose\Imaging\Model\Requests\ConvertImageRequest;
use Aspose\Imaging\Model\Requests\CreateConvertedImageRequest;
use Exception;
// Get ClientId and ClientSecret from https://dashboard.aspose.cloud/
// or use on-premise version (https://docs.aspose.cloud/imaging/getting-started/how-to-run-docker-container/)
$ImageFileName = "example_image.png";
$ImagesFolder = "ExampleImages";
$CloudFolder = "CloudImages";
$OutputFolder = "Output";
$clientSecret = null;
$clientId = null;
$baseUrl = "https://api.aspose.cloud";
$imagingConfig = new Configuration();
$imagingConfig->setClientSecret($clientSecret);
$imagingConfig->setClientId($clientId);
$imagingConfig->setBaseUrl($baseUrl);
$imagingApi = new ImagingApi($imagingConfig);
/**
* Export an image to another format.
*/
public function ConvertImageFromStorage()
{
$this->UploadSampleImageToCloud();
$inputImage = file_get_contents($this->ImagesFolder . DIRECTORY_SEPARATOR . $this->ImageFileName);
$request = new UploadFileRequest($this->CloudPath . DIRECTORY_SEPARATOR . $this->ImageName, $inputImage);
$response = self::$imagingApi->uploadFile($request);
if ($response->getErrors() != null && count($response->getErrors()) == 0)
echo ("Uploading errors count: " . count($response->getErrors()));
// Please refer to https://docs.aspose.cloud/imaging/supported-file-formats/#convert
// for possible output formats
$format = "bmp";
$folder = $this->CloudFolder; // Input file is saved at the desired folder in the storage
$storage = null; // Cloud Storage name
$request = new ConvertImageRequest($this->ImageFileName, $format, $folder, $storage);
$convertedImage = self::$imagingApi->convertImage($request);
// Save the image file to output folder
$convertedImageName = substr($this->ImageFileName, 0, strrpos($this->ImageFileName, ".") + 1) . "bmp";
$path = $this-> OutputFolder . DIRECTORY_SEPARATOR . $convertedImageName;
file_put_contents($path, $convertedImage);
}
/**
* Convert an image to another format. Image data is passed in a request stream.
*/
public function CreateConvertedImageFromRequest()
{
// Please refer to https://docs.aspose.cloud/imaging/supported-file-formats/#convert
// for possible output formats
$format = "bmp";
$outPath = null; // Path to updated file (if this is empty, response contains streamed image)
$storage = null; // Cloud Storage name
$inputStream = file_get_contents($this->ImagesFolder . DIRECTORY_SEPARATOR . $this->ImageFileName);
$request = new CreateConvertedImageRequest($inputStream, $format, $outPath, $storage);
$convertdImage = self::$imagingApi->createConvertedImage($request);
// Save the image file to output folder
$convertedImageName = substr($this->ImageFileName, 0, strrpos($this->ImageFileName, ".") + 1) . "bmp";
$path = $this-> OutputFolder . DIRECTORY_SEPARATOR . $convertedImageName;
file_put_contents($path, $convertedImage);
}
use Aspose\Imaging\Configuration;
use Aspose\Imaging\ImagingApi;
use Aspose\Imaging\Model\Requests\ConvertImageRequest;
use Aspose\Imaging\Model\Requests\CreateConvertedImageRequest;
use Exception;
// Get ClientId and ClientSecret from https://dashboard.aspose.cloud/
// or use on-premise version (https://docs.aspose.cloud/imaging/getting-started/how-to-run-docker-container/)
$ImageFileName = "example_image.png";
$ImagesFolder = "ExampleImages";
$CloudFolder = "CloudImages";
$OutputFolder = "Output";
$clientSecret = null;
$clientId = null;
$baseUrl = "https://api.aspose.cloud";
$imagingConfig = new Configuration();
$imagingConfig->setClientSecret($clientSecret);
$imagingConfig->setClientId($clientId);
$imagingConfig->setBaseUrl($baseUrl);
$imagingApi = new ImagingApi($imagingConfig);
/**
* Export an image to another format.
*/
public function ConvertImageFromStorage()
{
$this->UploadSampleImageToCloud();
$inputImage = file_get_contents($this->ImagesFolder . DIRECTORY_SEPARATOR . $this->ImageFileName);
$request = new UploadFileRequest($this->CloudPath . DIRECTORY_SEPARATOR . $this->ImageName, $inputImage);
$response = self::$imagingApi->uploadFile($request);
if ($response->getErrors() != null && count($response->getErrors()) == 0)
echo ("Uploading errors count: " . count($response->getErrors()));
// Please refer to https://docs.aspose.cloud/imaging/supported-file-formats/#convert
// for possible output formats
$format = "dicom";
$folder = $this->CloudFolder; // Input file is saved at the desired folder in the storage
$storage = null; // Cloud Storage name
$request = new ConvertImageRequest($this->ImageFileName, $format, $folder, $storage);
$convertedImage = self::$imagingApi->convertImage($request);
// Save the image file to output folder
$convertedImageName = substr($this->ImageFileName, 0, strrpos($this->ImageFileName, ".") + 1) . "dicom";
$path = $this-> OutputFolder . DIRECTORY_SEPARATOR . $convertedImageName;
file_put_contents($path, $convertedImage);
}
/**
* Convert an image to another format. Image data is passed in a request stream.
*/
public function CreateConvertedImageFromRequest()
{
// Please refer to https://docs.aspose.cloud/imaging/supported-file-formats/#convert
// for possible output formats
$format = "dicom";
$outPath = null; // Path to updated file (if this is empty, response contains streamed image)
$storage = null; // Cloud Storage name
$inputStream = file_get_contents($this->ImagesFolder . DIRECTORY_SEPARATOR . $this->ImageFileName);
$request = new CreateConvertedImageRequest($inputStream, $format, $outPath, $storage);
$convertdImage = self::$imagingApi->createConvertedImage($request);
// Save the image file to output folder
$convertedImageName = substr($this->ImageFileName, 0, strrpos($this->ImageFileName, ".") + 1) . "dicom";
$path = $this-> OutputFolder . DIRECTORY_SEPARATOR . $convertedImageName;
file_put_contents($path, $convertedImage);
}
use Aspose\Imaging\Configuration;
use Aspose\Imaging\ImagingApi;
use Aspose\Imaging\Model\Requests\ConvertImageRequest;
use Aspose\Imaging\Model\Requests\CreateConvertedImageRequest;
use Exception;
// Get ClientId and ClientSecret from https://dashboard.aspose.cloud/
// or use on-premise version (https://docs.aspose.cloud/imaging/getting-started/how-to-run-docker-container/)
$ImageFileName = "example_image.png";
$ImagesFolder = "ExampleImages";
$CloudFolder = "CloudImages";
$OutputFolder = "Output";
$clientSecret = null;
$clientId = null;
$baseUrl = "https://api.aspose.cloud";
$imagingConfig = new Configuration();
$imagingConfig->setClientSecret($clientSecret);
$imagingConfig->setClientId($clientId);
$imagingConfig->setBaseUrl($baseUrl);
$imagingApi = new ImagingApi($imagingConfig);
/**
* Export an image to another format.
*/
public function ConvertImageFromStorage()
{
$this->UploadSampleImageToCloud();
$inputImage = file_get_contents($this->ImagesFolder . DIRECTORY_SEPARATOR . $this->ImageFileName);
$request = new UploadFileRequest($this->CloudPath . DIRECTORY_SEPARATOR . $this->ImageName, $inputImage);
$response = self::$imagingApi->uploadFile($request);
if ($response->getErrors() != null && count($response->getErrors()) == 0)
echo ("Uploading errors count: " . count($response->getErrors()));
// Please refer to https://docs.aspose.cloud/imaging/supported-file-formats/#convert
// for possible output formats
$format = "gif";
$folder = $this->CloudFolder; // Input file is saved at the desired folder in the storage
$storage = null; // Cloud Storage name
$request = new ConvertImageRequest($this->ImageFileName, $format, $folder, $storage);
$convertedImage = self::$imagingApi->convertImage($request);
// Save the image file to output folder
$convertedImageName = substr($this->ImageFileName, 0, strrpos($this->ImageFileName, ".") + 1) . "gif";
$path = $this-> OutputFolder . DIRECTORY_SEPARATOR . $convertedImageName;
file_put_contents($path, $convertedImage);
}
/**
* Convert an image to another format. Image data is passed in a request stream.
*/
public function CreateConvertedImageFromRequest()
{
// Please refer to https://docs.aspose.cloud/imaging/supported-file-formats/#convert
// for possible output formats
$format = "gif";
$outPath = null; // Path to updated file (if this is empty, response contains streamed image)
$storage = null; // Cloud Storage name
$inputStream = file_get_contents($this->ImagesFolder . DIRECTORY_SEPARATOR . $this->ImageFileName);
$request = new CreateConvertedImageRequest($inputStream, $format, $outPath, $storage);
$convertdImage = self::$imagingApi->createConvertedImage($request);
// Save the image file to output folder
$convertedImageName = substr($this->ImageFileName, 0, strrpos($this->ImageFileName, ".") + 1) . "gif";
$path = $this-> OutputFolder . DIRECTORY_SEPARATOR . $convertedImageName;
file_put_contents($path, $convertedImage);
}
use Aspose\Imaging\Configuration;
use Aspose\Imaging\ImagingApi;
use Aspose\Imaging\Model\Requests\ConvertImageRequest;
use Aspose\Imaging\Model\Requests\CreateConvertedImageRequest;
use Exception;
// Get ClientId and ClientSecret from https://dashboard.aspose.cloud/
// or use on-premise version (https://docs.aspose.cloud/imaging/getting-started/how-to-run-docker-container/)
$ImageFileName = "example_image.png";
$ImagesFolder = "ExampleImages";
$CloudFolder = "CloudImages";
$OutputFolder = "Output";
$clientSecret = null;
$clientId = null;
$baseUrl = "https://api.aspose.cloud";
$imagingConfig = new Configuration();
$imagingConfig->setClientSecret($clientSecret);
$imagingConfig->setClientId($clientId);
$imagingConfig->setBaseUrl($baseUrl);
$imagingApi = new ImagingApi($imagingConfig);
/**
* Export an image to another format.
*/
public function ConvertImageFromStorage()
{
$this->UploadSampleImageToCloud();
$inputImage = file_get_contents($this->ImagesFolder . DIRECTORY_SEPARATOR . $this->ImageFileName);
$request = new UploadFileRequest($this->CloudPath . DIRECTORY_SEPARATOR . $this->ImageName, $inputImage);
$response = self::$imagingApi->uploadFile($request);
if ($response->getErrors() != null && count($response->getErrors()) == 0)
echo ("Uploading errors count: " . count($response->getErrors()));
// Please refer to https://docs.aspose.cloud/imaging/supported-file-formats/#convert
// for possible output formats
$format = "jpeg";
$folder = $this->CloudFolder; // Input file is saved at the desired folder in the storage
$storage = null; // Cloud Storage name
$request = new ConvertImageRequest($this->ImageFileName, $format, $folder, $storage);
$convertedImage = self::$imagingApi->convertImage($request);
// Save the image file to output folder
$convertedImageName = substr($this->ImageFileName, 0, strrpos($this->ImageFileName, ".") + 1) . "jpeg";
$path = $this-> OutputFolder . DIRECTORY_SEPARATOR . $convertedImageName;
file_put_contents($path, $convertedImage);
}
/**
* Convert an image to another format. Image data is passed in a request stream.
*/
public function CreateConvertedImageFromRequest()
{
// Please refer to https://docs.aspose.cloud/imaging/supported-file-formats/#convert
// for possible output formats
$format = "jpeg";
$outPath = null; // Path to updated file (if this is empty, response contains streamed image)
$storage = null; // Cloud Storage name
$inputStream = file_get_contents($this->ImagesFolder . DIRECTORY_SEPARATOR . $this->ImageFileName);
$request = new CreateConvertedImageRequest($inputStream, $format, $outPath, $storage);
$convertdImage = self::$imagingApi->createConvertedImage($request);
// Save the image file to output folder
$convertedImageName = substr($this->ImageFileName, 0, strrpos($this->ImageFileName, ".") + 1) . "jpeg";
$path = $this-> OutputFolder . DIRECTORY_SEPARATOR . $convertedImageName;
file_put_contents($path, $convertedImage);
}
use Aspose\Imaging\Configuration;
use Aspose\Imaging\ImagingApi;
use Aspose\Imaging\Model\Requests\ConvertImageRequest;
use Aspose\Imaging\Model\Requests\CreateConvertedImageRequest;
use Exception;
// Get ClientId and ClientSecret from https://dashboard.aspose.cloud/
// or use on-premise version (https://docs.aspose.cloud/imaging/getting-started/how-to-run-docker-container/)
$ImageFileName = "example_image.png";
$ImagesFolder = "ExampleImages";
$CloudFolder = "CloudImages";
$OutputFolder = "Output";
$clientSecret = null;
$clientId = null;
$baseUrl = "https://api.aspose.cloud";
$imagingConfig = new Configuration();
$imagingConfig->setClientSecret($clientSecret);
$imagingConfig->setClientId($clientId);
$imagingConfig->setBaseUrl($baseUrl);
$imagingApi = new ImagingApi($imagingConfig);
/**
* Export an image to another format.
*/
public function ConvertImageFromStorage()
{
$this->UploadSampleImageToCloud();
$inputImage = file_get_contents($this->ImagesFolder . DIRECTORY_SEPARATOR . $this->ImageFileName);
$request = new UploadFileRequest($this->CloudPath . DIRECTORY_SEPARATOR . $this->ImageName, $inputImage);
$response = self::$imagingApi->uploadFile($request);
if ($response->getErrors() != null && count($response->getErrors()) == 0)
echo ("Uploading errors count: " . count($response->getErrors()));
// Please refer to https://docs.aspose.cloud/imaging/supported-file-formats/#convert
// for possible output formats
$format = "jpeg2000";
$folder = $this->CloudFolder; // Input file is saved at the desired folder in the storage
$storage = null; // Cloud Storage name
$request = new ConvertImageRequest($this->ImageFileName, $format, $folder, $storage);
$convertedImage = self::$imagingApi->convertImage($request);
// Save the image file to output folder
$convertedImageName = substr($this->ImageFileName, 0, strrpos($this->ImageFileName, ".") + 1) . "jpeg2000";
$path = $this-> OutputFolder . DIRECTORY_SEPARATOR . $convertedImageName;
file_put_contents($path, $convertedImage);
}
/**
* Convert an image to another format. Image data is passed in a request stream.
*/
public function CreateConvertedImageFromRequest()
{
// Please refer to https://docs.aspose.cloud/imaging/supported-file-formats/#convert
// for possible output formats
$format = "jpeg2000";
$outPath = null; // Path to updated file (if this is empty, response contains streamed image)
$storage = null; // Cloud Storage name
$inputStream = file_get_contents($this->ImagesFolder . DIRECTORY_SEPARATOR . $this->ImageFileName);
$request = new CreateConvertedImageRequest($inputStream, $format, $outPath, $storage);
$convertdImage = self::$imagingApi->createConvertedImage($request);
// Save the image file to output folder
$convertedImageName = substr($this->ImageFileName, 0, strrpos($this->ImageFileName, ".") + 1) . "jpeg2000";
$path = $this-> OutputFolder . DIRECTORY_SEPARATOR . $convertedImageName;
file_put_contents($path, $convertedImage);
}
use Aspose\Imaging\Configuration;
use Aspose\Imaging\ImagingApi;
use Aspose\Imaging\Model\Requests\ConvertImageRequest;
use Aspose\Imaging\Model\Requests\CreateConvertedImageRequest;
use Exception;
// Get ClientId and ClientSecret from https://dashboard.aspose.cloud/
// or use on-premise version (https://docs.aspose.cloud/imaging/getting-started/how-to-run-docker-container/)
$ImageFileName = "example_image.png";
$ImagesFolder = "ExampleImages";
$CloudFolder = "CloudImages";
$OutputFolder = "Output";
$clientSecret = null;
$clientId = null;
$baseUrl = "https://api.aspose.cloud";
$imagingConfig = new Configuration();
$imagingConfig->setClientSecret($clientSecret);
$imagingConfig->setClientId($clientId);
$imagingConfig->setBaseUrl($baseUrl);
$imagingApi = new ImagingApi($imagingConfig);
/**
* Export an image to another format.
*/
public function ConvertImageFromStorage()
{
$this->UploadSampleImageToCloud();
$inputImage = file_get_contents($this->ImagesFolder . DIRECTORY_SEPARATOR . $this->ImageFileName);
$request = new UploadFileRequest($this->CloudPath . DIRECTORY_SEPARATOR . $this->ImageName, $inputImage);
$response = self::$imagingApi->uploadFile($request);
if ($response->getErrors() != null && count($response->getErrors()) == 0)
echo ("Uploading errors count: " . count($response->getErrors()));
// Please refer to https://docs.aspose.cloud/imaging/supported-file-formats/#convert
// for possible output formats
$format = "jpg";
$folder = $this->CloudFolder; // Input file is saved at the desired folder in the storage
$storage = null; // Cloud Storage name
$request = new ConvertImageRequest($this->ImageFileName, $format, $folder, $storage);
$convertedImage = self::$imagingApi->convertImage($request);
// Save the image file to output folder
$convertedImageName = substr($this->ImageFileName, 0, strrpos($this->ImageFileName, ".") + 1) . "jpg";
$path = $this-> OutputFolder . DIRECTORY_SEPARATOR . $convertedImageName;
file_put_contents($path, $convertedImage);
}
/**
* Convert an image to another format. Image data is passed in a request stream.
*/
public function CreateConvertedImageFromRequest()
{
// Please refer to https://docs.aspose.cloud/imaging/supported-file-formats/#convert
// for possible output formats
$format = "jpg";
$outPath = null; // Path to updated file (if this is empty, response contains streamed image)
$storage = null; // Cloud Storage name
$inputStream = file_get_contents($this->ImagesFolder . DIRECTORY_SEPARATOR . $this->ImageFileName);
$request = new CreateConvertedImageRequest($inputStream, $format, $outPath, $storage);
$convertdImage = self::$imagingApi->createConvertedImage($request);
// Save the image file to output folder
$convertedImageName = substr($this->ImageFileName, 0, strrpos($this->ImageFileName, ".") + 1) . "jpg";
$path = $this-> OutputFolder . DIRECTORY_SEPARATOR . $convertedImageName;
file_put_contents($path, $convertedImage);
}
use Aspose\Imaging\Configuration;
use Aspose\Imaging\ImagingApi;
use Aspose\Imaging\Model\Requests\ConvertImageRequest;
use Aspose\Imaging\Model\Requests\CreateConvertedImageRequest;
use Exception;
// Get ClientId and ClientSecret from https://dashboard.aspose.cloud/
// or use on-premise version (https://docs.aspose.cloud/imaging/getting-started/how-to-run-docker-container/)
$ImageFileName = "example_image.png";
$ImagesFolder = "ExampleImages";
$CloudFolder = "CloudImages";
$OutputFolder = "Output";
$clientSecret = null;
$clientId = null;
$baseUrl = "https://api.aspose.cloud";
$imagingConfig = new Configuration();
$imagingConfig->setClientSecret($clientSecret);
$imagingConfig->setClientId($clientId);
$imagingConfig->setBaseUrl($baseUrl);
$imagingApi = new ImagingApi($imagingConfig);
/**
* Export an image to another format.
*/
public function ConvertImageFromStorage()
{
$this->UploadSampleImageToCloud();
$inputImage = file_get_contents($this->ImagesFolder . DIRECTORY_SEPARATOR . $this->ImageFileName);
$request = new UploadFileRequest($this->CloudPath . DIRECTORY_SEPARATOR . $this->ImageName, $inputImage);
$response = self::$imagingApi->uploadFile($request);
if ($response->getErrors() != null && count($response->getErrors()) == 0)
echo ("Uploading errors count: " . count($response->getErrors()));
// Please refer to https://docs.aspose.cloud/imaging/supported-file-formats/#convert
// for possible output formats
$format = "pdf";
$folder = $this->CloudFolder; // Input file is saved at the desired folder in the storage
$storage = null; // Cloud Storage name
$request = new ConvertImageRequest($this->ImageFileName, $format, $folder, $storage);
$convertedImage = self::$imagingApi->convertImage($request);
// Save the image file to output folder
$convertedImageName = substr($this->ImageFileName, 0, strrpos($this->ImageFileName, ".") + 1) . "pdf";
$path = $this-> OutputFolder . DIRECTORY_SEPARATOR . $convertedImageName;
file_put_contents($path, $convertedImage);
}
/**
* Convert an image to another format. Image data is passed in a request stream.
*/
public function CreateConvertedImageFromRequest()
{
// Please refer to https://docs.aspose.cloud/imaging/supported-file-formats/#convert
// for possible output formats
$format = "pdf";
$outPath = null; // Path to updated file (if this is empty, response contains streamed image)
$storage = null; // Cloud Storage name
$inputStream = file_get_contents($this->ImagesFolder . DIRECTORY_SEPARATOR . $this->ImageFileName);
$request = new CreateConvertedImageRequest($inputStream, $format, $outPath, $storage);
$convertdImage = self::$imagingApi->createConvertedImage($request);
// Save the image file to output folder
$convertedImageName = substr($this->ImageFileName, 0, strrpos($this->ImageFileName, ".") + 1) . "pdf";
$path = $this-> OutputFolder . DIRECTORY_SEPARATOR . $convertedImageName;
file_put_contents($path, $convertedImage);
}
use Aspose\Imaging\Configuration;
use Aspose\Imaging\ImagingApi;
use Aspose\Imaging\Model\Requests\ConvertImageRequest;
use Aspose\Imaging\Model\Requests\CreateConvertedImageRequest;
use Exception;
// Get ClientId and ClientSecret from https://dashboard.aspose.cloud/
// or use on-premise version (https://docs.aspose.cloud/imaging/getting-started/how-to-run-docker-container/)
$ImageFileName = "example_image.png";
$ImagesFolder = "ExampleImages";
$CloudFolder = "CloudImages";
$OutputFolder = "Output";
$clientSecret = null;
$clientId = null;
$baseUrl = "https://api.aspose.cloud";
$imagingConfig = new Configuration();
$imagingConfig->setClientSecret($clientSecret);
$imagingConfig->setClientId($clientId);
$imagingConfig->setBaseUrl($baseUrl);
$imagingApi = new ImagingApi($imagingConfig);
/**
* Export an image to another format.
*/
public function ConvertImageFromStorage()
{
$this->UploadSampleImageToCloud();
$inputImage = file_get_contents($this->ImagesFolder . DIRECTORY_SEPARATOR . $this->ImageFileName);
$request = new UploadFileRequest($this->CloudPath . DIRECTORY_SEPARATOR . $this->ImageName, $inputImage);
$response = self::$imagingApi->uploadFile($request);
if ($response->getErrors() != null && count($response->getErrors()) == 0)
echo ("Uploading errors count: " . count($response->getErrors()));
// Please refer to https://docs.aspose.cloud/imaging/supported-file-formats/#convert
// for possible output formats
$format = "psd";
$folder = $this->CloudFolder; // Input file is saved at the desired folder in the storage
$storage = null; // Cloud Storage name
$request = new ConvertImageRequest($this->ImageFileName, $format, $folder, $storage);
$convertedImage = self::$imagingApi->convertImage($request);
// Save the image file to output folder
$convertedImageName = substr($this->ImageFileName, 0, strrpos($this->ImageFileName, ".") + 1) . "psd";
$path = $this-> OutputFolder . DIRECTORY_SEPARATOR . $convertedImageName;
file_put_contents($path, $convertedImage);
}
/**
* Convert an image to another format. Image data is passed in a request stream.
*/
public function CreateConvertedImageFromRequest()
{
// Please refer to https://docs.aspose.cloud/imaging/supported-file-formats/#convert
// for possible output formats
$format = "psd";
$outPath = null; // Path to updated file (if this is empty, response contains streamed image)
$storage = null; // Cloud Storage name
$inputStream = file_get_contents($this->ImagesFolder . DIRECTORY_SEPARATOR . $this->ImageFileName);
$request = new CreateConvertedImageRequest($inputStream, $format, $outPath, $storage);
$convertdImage = self::$imagingApi->createConvertedImage($request);
// Save the image file to output folder
$convertedImageName = substr($this->ImageFileName, 0, strrpos($this->ImageFileName, ".") + 1) . "psd";
$path = $this-> OutputFolder . DIRECTORY_SEPARATOR . $convertedImageName;
file_put_contents($path, $convertedImage);
}
use Aspose\Imaging\Configuration;
use Aspose\Imaging\ImagingApi;
use Aspose\Imaging\Model\Requests\ConvertImageRequest;
use Aspose\Imaging\Model\Requests\CreateConvertedImageRequest;
use Exception;
// Get ClientId and ClientSecret from https://dashboard.aspose.cloud/
// or use on-premise version (https://docs.aspose.cloud/imaging/getting-started/how-to-run-docker-container/)
$ImageFileName = "example_image.png";
$ImagesFolder = "ExampleImages";
$CloudFolder = "CloudImages";
$OutputFolder = "Output";
$clientSecret = null;
$clientId = null;
$baseUrl = "https://api.aspose.cloud";
$imagingConfig = new Configuration();
$imagingConfig->setClientSecret($clientSecret);
$imagingConfig->setClientId($clientId);
$imagingConfig->setBaseUrl($baseUrl);
$imagingApi = new ImagingApi($imagingConfig);
/**
* Export an image to another format.
*/
public function ConvertImageFromStorage()
{
$this->UploadSampleImageToCloud();
$inputImage = file_get_contents($this->ImagesFolder . DIRECTORY_SEPARATOR . $this->ImageFileName);
$request = new UploadFileRequest($this->CloudPath . DIRECTORY_SEPARATOR . $this->ImageName, $inputImage);
$response = self::$imagingApi->uploadFile($request);
if ($response->getErrors() != null && count($response->getErrors()) == 0)
echo ("Uploading errors count: " . count($response->getErrors()));
// Please refer to https://docs.aspose.cloud/imaging/supported-file-formats/#convert
// for possible output formats
$format = "tga";
$folder = $this->CloudFolder; // Input file is saved at the desired folder in the storage
$storage = null; // Cloud Storage name
$request = new ConvertImageRequest($this->ImageFileName, $format, $folder, $storage);
$convertedImage = self::$imagingApi->convertImage($request);
// Save the image file to output folder
$convertedImageName = substr($this->ImageFileName, 0, strrpos($this->ImageFileName, ".") + 1) . "tga";
$path = $this-> OutputFolder . DIRECTORY_SEPARATOR . $convertedImageName;
file_put_contents($path, $convertedImage);
}
/**
* Convert an image to another format. Image data is passed in a request stream.
*/
public function CreateConvertedImageFromRequest()
{
// Please refer to https://docs.aspose.cloud/imaging/supported-file-formats/#convert
// for possible output formats
$format = "tga";
$outPath = null; // Path to updated file (if this is empty, response contains streamed image)
$storage = null; // Cloud Storage name
$inputStream = file_get_contents($this->ImagesFolder . DIRECTORY_SEPARATOR . $this->ImageFileName);
$request = new CreateConvertedImageRequest($inputStream, $format, $outPath, $storage);
$convertdImage = self::$imagingApi->createConvertedImage($request);
// Save the image file to output folder
$convertedImageName = substr($this->ImageFileName, 0, strrpos($this->ImageFileName, ".") + 1) . "tga";
$path = $this-> OutputFolder . DIRECTORY_SEPARATOR . $convertedImageName;
file_put_contents($path, $convertedImage);
}
use Aspose\Imaging\Configuration;
use Aspose\Imaging\ImagingApi;
use Aspose\Imaging\Model\Requests\ConvertImageRequest;
use Aspose\Imaging\Model\Requests\CreateConvertedImageRequest;
use Exception;
// Get ClientId and ClientSecret from https://dashboard.aspose.cloud/
// or use on-premise version (https://docs.aspose.cloud/imaging/getting-started/how-to-run-docker-container/)
$ImageFileName = "example_image.png";
$ImagesFolder = "ExampleImages";
$CloudFolder = "CloudImages";
$OutputFolder = "Output";
$clientSecret = null;
$clientId = null;
$baseUrl = "https://api.aspose.cloud";
$imagingConfig = new Configuration();
$imagingConfig->setClientSecret($clientSecret);
$imagingConfig->setClientId($clientId);
$imagingConfig->setBaseUrl($baseUrl);
$imagingApi = new ImagingApi($imagingConfig);
/**
* Export an image to another format.
*/
public function ConvertImageFromStorage()
{
$this->UploadSampleImageToCloud();
$inputImage = file_get_contents($this->ImagesFolder . DIRECTORY_SEPARATOR . $this->ImageFileName);
$request = new UploadFileRequest($this->CloudPath . DIRECTORY_SEPARATOR . $this->ImageName, $inputImage);
$response = self::$imagingApi->uploadFile($request);
if ($response->getErrors() != null && count($response->getErrors()) == 0)
echo ("Uploading errors count: " . count($response->getErrors()));
// Please refer to https://docs.aspose.cloud/imaging/supported-file-formats/#convert
// for possible output formats
$format = "tiff";
$folder = $this->CloudFolder; // Input file is saved at the desired folder in the storage
$storage = null; // Cloud Storage name
$request = new ConvertImageRequest($this->ImageFileName, $format, $folder, $storage);
$convertedImage = self::$imagingApi->convertImage($request);
// Save the image file to output folder
$convertedImageName = substr($this->ImageFileName, 0, strrpos($this->ImageFileName, ".") + 1) . "tiff";
$path = $this-> OutputFolder . DIRECTORY_SEPARATOR . $convertedImageName;
file_put_contents($path, $convertedImage);
}
/**
* Convert an image to another format. Image data is passed in a request stream.
*/
public function CreateConvertedImageFromRequest()
{
// Please refer to https://docs.aspose.cloud/imaging/supported-file-formats/#convert
// for possible output formats
$format = "tiff";
$outPath = null; // Path to updated file (if this is empty, response contains streamed image)
$storage = null; // Cloud Storage name
$inputStream = file_get_contents($this->ImagesFolder . DIRECTORY_SEPARATOR . $this->ImageFileName);
$request = new CreateConvertedImageRequest($inputStream, $format, $outPath, $storage);
$convertdImage = self::$imagingApi->createConvertedImage($request);
// Save the image file to output folder
$convertedImageName = substr($this->ImageFileName, 0, strrpos($this->ImageFileName, ".") + 1) . "tiff";
$path = $this-> OutputFolder . DIRECTORY_SEPARATOR . $convertedImageName;
file_put_contents($path, $convertedImage);
}
use Aspose\Imaging\Configuration;
use Aspose\Imaging\ImagingApi;
use Aspose\Imaging\Model\Requests\ConvertImageRequest;
use Aspose\Imaging\Model\Requests\CreateConvertedImageRequest;
use Exception;
// Get ClientId and ClientSecret from https://dashboard.aspose.cloud/
// or use on-premise version (https://docs.aspose.cloud/imaging/getting-started/how-to-run-docker-container/)
$ImageFileName = "example_image.png";
$ImagesFolder = "ExampleImages";
$CloudFolder = "CloudImages";
$OutputFolder = "Output";
$clientSecret = null;
$clientId = null;
$baseUrl = "https://api.aspose.cloud";
$imagingConfig = new Configuration();
$imagingConfig->setClientSecret($clientSecret);
$imagingConfig->setClientId($clientId);
$imagingConfig->setBaseUrl($baseUrl);
$imagingApi = new ImagingApi($imagingConfig);
/**
* Export an image to another format.
*/
public function ConvertImageFromStorage()
{
$this->UploadSampleImageToCloud();
$inputImage = file_get_contents($this->ImagesFolder . DIRECTORY_SEPARATOR . $this->ImageFileName);
$request = new UploadFileRequest($this->CloudPath . DIRECTORY_SEPARATOR . $this->ImageName, $inputImage);
$response = self::$imagingApi->uploadFile($request);
if ($response->getErrors() != null && count($response->getErrors()) == 0)
echo ("Uploading errors count: " . count($response->getErrors()));
// Please refer to https://docs.aspose.cloud/imaging/supported-file-formats/#convert
// for possible output formats
$format = "webp";
$folder = $this->CloudFolder; // Input file is saved at the desired folder in the storage
$storage = null; // Cloud Storage name
$request = new ConvertImageRequest($this->ImageFileName, $format, $folder, $storage);
$convertedImage = self::$imagingApi->convertImage($request);
// Save the image file to output folder
$convertedImageName = substr($this->ImageFileName, 0, strrpos($this->ImageFileName, ".") + 1) . "webp";
$path = $this-> OutputFolder . DIRECTORY_SEPARATOR . $convertedImageName;
file_put_contents($path, $convertedImage);
}
/**
* Convert an image to another format. Image data is passed in a request stream.
*/
public function CreateConvertedImageFromRequest()
{
// Please refer to https://docs.aspose.cloud/imaging/supported-file-formats/#convert
// for possible output formats
$format = "webp";
$outPath = null; // Path to updated file (if this is empty, response contains streamed image)
$storage = null; // Cloud Storage name
$inputStream = file_get_contents($this->ImagesFolder . DIRECTORY_SEPARATOR . $this->ImageFileName);
$request = new CreateConvertedImageRequest($inputStream, $format, $outPath, $storage);
$convertdImage = self::$imagingApi->createConvertedImage($request);
// Save the image file to output folder
$convertedImageName = substr($this->ImageFileName, 0, strrpos($this->ImageFileName, ".") + 1) . "webp";
$path = $this-> OutputFolder . DIRECTORY_SEPARATOR . $convertedImageName;
file_put_contents($path, $convertedImage);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment