{"id":15693983,"url":"https://github.com/bnomei/kirby3-cloudconvert","last_synced_at":"2025-03-11T19:31:24.455Z","repository":{"id":37587774,"uuid":"153888798","full_name":"bnomei/kirby3-cloudconvert","owner":"bnomei","description":"Plugin to convert anything to anything using cloudconvert","archived":true,"fork":false,"pushed_at":"2024-11-23T17:34:30.000Z","size":796,"stargazers_count":8,"open_issues_count":4,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-07T04:17:34.674Z","etag":null,"topics":["anything","cloudconvert","convert","convert-images","kirby3","kirby3-cms","kirby3-plugin"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bnomei.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"bnomei","patreon":"bnomei","open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":["https://buymeacoff.ee/bnomei","https://paypal.me/bnomei"]}},"created_at":"2018-10-20T09:14:49.000Z","updated_at":"2024-11-23T19:11:26.000Z","dependencies_parsed_at":"2024-10-24T01:19:02.637Z","dependency_job_id":"3aed9fab-abf3-42f1-80dd-f47df1470ced","html_url":"https://github.com/bnomei/kirby3-cloudconvert","commit_stats":{"total_commits":31,"total_committers":2,"mean_commits":15.5,"dds":"0.25806451612903225","last_synced_commit":"28b96ace15deaa9575308f31b5b83df2bcb48f9a"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bnomei%2Fkirby3-cloudconvert","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bnomei%2Fkirby3-cloudconvert/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bnomei%2Fkirby3-cloudconvert/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bnomei%2Fkirby3-cloudconvert/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bnomei","download_url":"https://codeload.github.com/bnomei/kirby3-cloudconvert/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243098779,"owners_count":20236095,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["anything","cloudconvert","convert","convert-images","kirby3","kirby3-cms","kirby3-plugin"],"created_at":"2024-10-03T18:50:57.556Z","updated_at":"2025-03-11T19:31:24.448Z","avatar_url":"https://github.com/bnomei.png","language":"PHP","funding_links":["https://github.com/sponsors/bnomei","https://patreon.com/bnomei","https://buymeacoff.ee/bnomei","https://paypal.me/bnomei"],"categories":[],"sub_categories":[],"readme":"# Kirby Cloudconvert\n\n![Release](https://flat.badgen.net/packagist/v/bnomei/kirby3-cloudconvert?color=ae81ff)\n![Downloads](https://flat.badgen.net/packagist/dt/bnomei/kirby3-cloudconvert?color=272822)\n[![Build Status](https://flat.badgen.net/travis/bnomei/kirby3-cloudconvert)](https://travis-ci.com/bnomei/kirby3-cloudconvert)\n[![Coverage Status](https://flat.badgen.net/coveralls/c/github/bnomei/kirby3-cloudconvert)](https://coveralls.io/github/bnomei/kirby3-cloudconvert) \n[![Maintainability](https://flat.badgen.net/codeclimate/maintainability/bnomei/kirby3-cloudconvert)](https://codeclimate.com/github/bnomei/kirby3-cloudconvert) \n[![Twitter](https://flat.badgen.net/badge/twitter/bnomei?color=66d9ef)](https://twitter.com/bnomei)\n\nPlugin to convert anything to anything using [cloudconvert](https://cloudconvert.com/).\n\n## Installation\n\n- unzip [master.zip](https://github.com/bnomei/kirby3-cloudconvert/archive/master.zip) as folder `site/plugins/kirby3-cloudconvert` or\n- `git submodule add https://github.com/bnomei/kirby3-cloudconvert.git site/plugins/kirby3-cloudconvert` or\n- `composer require bnomei/kirby3-cloudconvert`\n\n## How to convert files on demand (synchronously)?\n\n### Example 1: docx to pdf\n\n```php\nif($fileWord = $page-\u003efile('test.docx')) {\n    $filePDF = $fileWord-\u003ecloudconvert(\n        [\n            'inputformat' =\u003e 'docx',\n            'outputformat' =\u003e 'pdf',\n        ], \n        str_replace('.docx', '.pdf', $fileWord-\u003eroot()),\n        false // wait for conversion to be done\n    );\n    echo $fileWord-\u003eurl().PHP_EOL;\n    if($filePDF) {\n        echo $filePDF-\u003eurl();\n    }\n}\n```\n\n## Hooks: How to convert files on upload/replace (asynchronously by default)?\n### Example 2: gif to webm and mp4\n\nIn Kirbys config file add this... then use panel to upload a gif to an image/file section.\n\n```php\nfunction customConvertHook($file) {\n    if($file-\u003eextension() == 'gif') {\n\n        $file-\u003ecloudconvert(\n            [\n                'inputformat' =\u003e 'gif',\n                'outputformat' =\u003e 'webm',\n                'save' =\u003e true, // keep file at cloud to avoid another download from cloudconvert-server\n            ]\n        );\n\n        $file-\u003ecloudconvert(\n            [\n                'inputformat' =\u003e 'gif',\n                'outputformat' =\u003e 'mp4',\n            ]\n        );\n    }\n}\n\nreturn [\n    // ... other config settings\n    'hooks' =\u003e [\n        'file.create:after' =\u003e function($file) {\n            customConvertHook($file);\n        },\n        'file.replace:after' =\u003e function($newFile, $oldFile) {\n            customConvertHook($newFile);\n        },\n    ]\n];\n```\n\n## Other Usecases\n\n### Example 3: convert ai to svg and optimize\nThis example shows how to use this plugin with my [thumb imageoptim plugin](https://github.com/bnomei/kirby3-thumb-imageoptim).\n\n```php\n$fileSvg = $file-\u003ecloudconvert(\n    [\n        'inputformat' =\u003e 'ai',\n        'outputformat' =\u003e 'svg',\n    ], \n    null, // auto-rename with extension\n    false // on-demand aka synchonous aka wait\n);\nif($fileSvg) {\n    // NOTE: resize() is called to trigger stuff like optimziers (see thumb-imageoptim plugin)\n    $fileSvgOptimized = $fileSvg-\u003eresize();\n    echo svg($fileSvgOptimized-\u003eroot()); // use kirbys svg helper to inline the svg\n}\n```\n\n### Example 4: How to convert image files for srcsets? jpg to webp.\nThis example shows how to use this plugin with my [srcset plugin](https://github.com/bnomei/kirby3-srcset).\n\n**config file**\n```php\nreturn [\n    // ... other settings\n    'bnomei.srcset.types' =\u003e ['jpg', 'webp'],\n    'bnomei.srcset.resize' =\u003e function (\\Kirby\\Cms\\File $file, int $width, string $type) {\n        // NOTE: resize() is called to trigger stuff like optimziers (see thumb-imageoptim plugin)\n\n        // use jpg to create webp\n        if($file-\u003eextension() == 'jpg' \u0026\u0026 $type == 'webp') {\n            $fileWebp = $file-\u003ecloudconvert(\n                [\n                    'inputformat' =\u003e 'jpg',\n                    'outputformat' =\u003e 'webp',\n                ], \n                null, // auto-rename with extension\n                false // on-demand aka synchonous aka wait\n            );\n            if($fileWebp) {\n                return $fileWebp-\u003eresize($width);\n            }\n        }\n        // otherwise default to returning image\n        return $file-\u003eresize($width);\n    }\n];\n```\n\n## Global cloudconvert helper function\n\nThis plugin provides a helper function to call the cloudconvert api.\n\n```php\n$obj = cloudconvert($options); // will change extension but keep path\n$obj = cloudconvert($options, $outputPath); // provide different path\n$obj = cloudconvert($options, $outputPath, $async); // a/sync\n```\n\n**Retrun Values**\n\n- `Kirby\\Cms\\File` if `$options['file']` is one as well and `$async == false`\n- otherwise it returns an instance of `CloudConvert\\Process`\n- or `null` on error\n\n## Performance\n\n**TD;DR**\nCalling File-Method has best performance since it only converts the file if it was modified or is new.\n\n### File-Object\nUsing `Kirby\\Cms\\File` object for `$options['file']` is recommended. In that case the modified timestamp will be checked against a cached value and a conversion triggered only if a file was modified or output does not exist. This is the default behaviour for the FileMethod provided by this plugin.\n\n\u003e DANGER: There is no check (yet) if a file is currently processed by cloudconvert. This might be improved at a later point.\n\n### Path\nWhen a path is used then file will be created only if ouput does not exist. You need to do modification checks and removing of old files yourself before starting the conversion.\n\n## Settings\n\n| bnomei.cloudconvert.      | Default        | Description               |            \n|---------------------------|----------------|---------------------------|\n| apikey | `null` | your cloudconvert apikey as string |\n| convert | `callback` | asynchronous or synchronous conversion depending on params. |\n| async | `true` | |\n| options | `['input' =\u003e 'download']` | By default this plugin requires the file to be public otherwise use `upload` here. On localhost `upload` is used as a default. |\n| log.enabled | `false` | |\n| log | `callback` | to `kirbyLog()` |\n\n\u003e TIP: you can also set a callback if you use the [dotenv Plugin](https://github.com/bnomei/kirby3-dotenv)\n\u003e `'bnomei.cloudconvert.apikey' =\u003e function() { return env('CLOUDCONVERT_APIKEY'); },`\n\n\u003e TIP: consider setting up [presets](https://cloudconvert.com/presets) to manage your settings from within the cloudconvert dashboard instead of the Kirby config file.\n\n## Disclaimer\n\nThis plugin is provided \"as is\" with no guarantee. Use it at your own risk and always test it yourself before using it in a production environment. If you find any issues, please [create a new issue](https://github.com/bnomei/kirby3-cloudconvert/issues/new).\n\n## License\n\n[MIT](https://opensource.org/licenses/MIT)\n\nIt is discouraged to use this plugin in any project that promotes racism, sexism, homophobia, animal abuse, violence or any other form of hate speech.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbnomei%2Fkirby3-cloudconvert","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbnomei%2Fkirby3-cloudconvert","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbnomei%2Fkirby3-cloudconvert/lists"}