robbiepaul / cloudconvert-laravel

A Laravel wrapper for the CloudConvert API
177 stars 34 forks source link

Converting PDF into JPG : Multiple output files #32

Closed AmirAmin closed 8 years ago

AmirAmin commented 8 years ago

Hello,

Right now converting from PDF to JPG creates Multiple output files.

So, Is there a method to deal with output.files instead of downloading the zip file?

https://cloudconvert.com/api/conversions#snippetDownloadMultipleRaw

Regards,

AmirAmin commented 8 years ago

Hello,

I discovered that "CloudConvert::useProcess" is already saving each image separately.

Thanks

robbiepaul commented 8 years ago

@AmirAmin Yes that's correct. The wrapper downloads the individual files, it doesn't download a zip file.

AmirAmin commented 8 years ago

@robbiepaul You guys did a really great job, Two more small questions please :

1) Right now i am using the following to convert PDF into JPG and upload the images to S3,

CloudConvert::file('http://www.gnfiliaton.gr/sites/default/files/20131231103232738561744.pdf')
            ->callback('http://url.com/callback')
            ->quality(80)
            ->convert(CloudConvert::S3('uploads/catalogue/issue/'));

But it is giving me error, as it requires to mention .jpg at the end of the parameter, and if i do that, it created a folder with the name ".jpg" and put the pictures inside it.

Do you have an idea of how to fix this issue?

2) What if i want to set max height or width for the generated jpg files ?

Regards,

robbiepaul commented 8 years ago

@AmirAmin 1) I haven't tested it, but this should be possible

CloudConvert::file('http://www.gnfiliaton.gr/sites/default/files/20131231103232738561744.pdf')
            ->callback('http://url.com/callback')
            ->quality(80)
            ->convert( CloudConvert::S3('jpg', [
                'path' => 'uploads/catalogue/issue/'
            ]));

2) The CloudConvert API allows for quite a few 'converter options' when starting a process. Check out the API Console for more info. For example you could do:

CloudConvert::file('http://www.gnfiliaton.gr/sites/default/files/20131231103232738561744.pdf')
            ->withOptions([
                'quality' => 80,
                'resize' => '500x400',
                'resizemode' => 'crop' // (optional) or 'scale' 
            ])
            ->callback('http://url.com/callback')
            ->convert( CloudConvert::S3('jpg', [
                'path' => 'uploads/catalogue/issue/'
            ]));

Alternatively if you want even more control over editing the images you could use a package like Intervention Image in your callback script.

AmirAmin commented 8 years ago

@robbiepaul

1) The solution for the path didn't work, it is giving "Invalid format" error. The same error as before, you have to add a file name at the end of the 'path' including the ext. for ex: 'path' => 'uploads/catalogue/issue/1.jpg' to make it work, and unfortunately it creates a folder with this name '1.jpg' and store the images inside it.

2) Resize option is working perfect.

Regards,

robbiepaul commented 8 years ago

@AmirAmin I've pushed a fix to allow custom paths (see: d871d75e4358f06cb9e2a9034efe797b3b7f429c)

Just run composer update robbiep/cloudconvert-laravel and the following code should work:

CloudConvert::file('http://www.gnfiliaton.gr/sites/default/files/20131231103232738561744.pdf')
            ->withOptions([
                'quality' => 80,
                'resize' => '500x400',
                'resizemode' => 'crop' // (optional) or 'scale' 
            ])
            ->callback('http://url.com/callback')
            ->convert( CloudConvert::S3('jpg', [
                'path' => 'uploads/catalogue/issue/'
            ]));
AmirAmin commented 8 years ago

It is working perfect, Thanks Bro