PHP code example of markocupic / cloudconvert-bundle
1. Go to this page and download the library: Download markocupic/cloudconvert-bundle library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
markocupic / cloudconvert-bundle example snippets
declare(strict_types=1);
namespace App\Controller;
use Contao\CoreBundle\Framework\ContaoFramework;
use Contao\System;
use Markocupic\CloudconvertBundle\Conversion\ConvertFile;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Component\Routing\Annotation\Route;
#[Route('/cloudconvert_demo', name: CloudconvertDemoController::class, defaults: ['_scope' => 'frontend'])]
class CloudconvertDemoController extends AbstractController
{
public function __construct(
private readonly ContaoFramework $framework,
private readonly ConvertFile $convertFile,
){}
/**
* @throws \Exception
*/
public function __invoke(): BinaryFileResponse
{
$this->framework->initialize();
$projectDir = System::getContainer()->getParameter('kernel.project_dir');
$sourcePath = $projectDir.'/files/mswordfile.docx';
// Basic example (minimal configuration):
// Convert from docx to pdf
$objSplFile = $this->convertFile
->file($sourcePath)
// Save converted file in the same
// directory as the source file.
->convertTo('pdf')
;
$sourcePath = $projectDir.'/files/samplesound.wav';
// Convert from wav to mp3
$objSplFile = $this->convertFile
->reset()
->file($sourcePath)
->convertTo('mp3')
;
$sourcePath = $projectDir.'/files/image.jpg';
// A slightly more sophisticated example:
$objSplFile = $this->convertFile
->reset()
->file($sourcePath)
// Sandbox API key has to be set in config/config.yaml
->sandbox(true)
->uncached(false) // Enable cache
->setCacheHashCode('566TZZUUTTAGHJKUZT') // use the hash of your file to get the file from the cache directory
// For a full list of possible options
// please visit https://cloudconvert.com/api/v2/convert#convert-tasks
->setOption('width', 1200)
->setOption('quality', 90)
// Convert docx file into the png format and
// save file in a different directory.
// For a full list of supported formats
// please visit https://cloudconvert.com/api/v2/convert#convert-formats
->convertTo('png', 'files/images/my_new_image.png')
;
// Send the converted file to the browser
return $this->file($objSplFile->getRealPath());
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.