These examples demonstrate common Image to Image API workflows via HTTP API.
You can run the examples below with the displayed API credentials. Update the input URLs and filenames as needed.
Use a Bash-compatible shell.
Basic options
-u — Supply your username and API key.-F — Send a form field.-o — Save the response to a file.-f — Report HTTP errors as command failures.-s -S — Hide the progress meter while keeping error messages.File input
file=@document.png — Upload a local file.Diagnostics
--fail-with-body
— Use instead of -f to retain the error response body.
-D — Save response headers to a file.-w — Print response information;
the diagnostic example
prints the HTTP status.
Install Requests with
python3 -m pip install requests. Save an example as
convert.py and run it with python3 convert.py.
Request options
auth — Supply your username and API key using HTTP Basic authentication.data — Send form fields; Requests encodes their values.files — Upload files opened in binary mode. Requests sets the multipart boundary.allow_redirects=False — Return the endpoint's response without following redirects.Response handling
raise_for_status() — Raise an exception for HTTP errors before opening the output file.response.content — Save the response bytes to a file opened with "wb".with — Close opened files even if the request or output write fails.
Connection errors raise exceptions. The examples do not set a client timeout or
retry requests. If you add a timeout, allow for conversion time;
Requests applies connection and read timeouts, not an overall conversion deadline.
The diagnostic example
saves response headers and body and prints the HTTP status before calling
raise_for_status(), so an HTTP error still leaves diagnostic files.
Use Node.js with its built-in Fetch API; no HTTP package is needed.
Save an example as convert.mjs and run it with
node convert.mjs. The .mjs extension enables imports
and top-level await.
Request options
Authorization — Send your username and API key using HTTP Basic authentication.FormData — Send form fields and files. Fetch sets the multipart boundary.readFile and Blob — Read uploads as bytes into memory and include their filenames.redirect: 'manual' — Return the endpoint's response without following redirects.Response handling
response.arrayBuffer() — Read the response bytes into memory.response.status — Check for HTTP errors before opening the output file; Fetch does not throw for HTTP errors itself.writeFile — Save the bytes to the output file. File and connection errors propagate as exceptions.
The examples use Fetch's native connection, response-header, and body inactivity
limits, which depend on the Node.js runtime. They do not set an overall conversion
deadline or retry requests. Allow for conversion time if you add a timeout using
an AbortSignal.
The diagnostic example saves response headers and body and prints the HTTP status before throwing on an HTTP error, so diagnostic files remain available.
Install Axios with npm install axios. Save an example as
convert.mjs and run it with node convert.mjs.
The .mjs extension enables imports and top-level await.
Request options
auth — Send your username and API key using HTTP Basic authentication.FormData — Send form fields and files. Axios sets the multipart boundary.readFile and Blob — Read uploads as bytes into memory and include their filenames.maxRedirects: 0 — Return the endpoint's response without following redirects.Response handling
responseType: 'arraybuffer' — Read the response as bytes.validateStatus — Reject HTTP errors before writing the output file.writeFile — Save the response bytes to the output file.Axios does not set an overall timeout by default. Allow for conversion time if you add one. Failed requests and file writes produce an error message and a nonzero exit status; the error handler prints only the message so request credentials are not included.
The diagnostic example saves response headers and body and prints the HTTP status before reporting an HTTP error, so diagnostic files remain available.
Install Guzzle with composer require guzzlehttp/guzzle.
Save an example as convert.php beside your vendor
directory and run it with php convert.php.
Request options
auth — Send your username and API key using HTTP Basic authentication.multipart — Send form fields and files. Guzzle sets the multipart boundary.Utils::tryFopen — Open input files as binary streams for upload.'allow_redirects' => false — Return the endpoint's response without following redirects.Response handling
'http_errors' => false — Inspect the HTTP status before writing the output file.getBody — Read the response as a binary string.file_put_contents — Save the response bytes and check that the entire result was written.Guzzle does not set an overall timeout by default. Allow for conversion time if you add one. Failed requests and file writes produce an error message and a nonzero exit status.
The diagnostic example saves response headers and body and prints the HTTP status before reporting an HTTP error, so diagnostic files remain available.
curl -f -s -S \ -u 'demo:demo' \ -o logo.jpg \ -F file=@logo.png \ -F input_format=image \ -F output_format=jpg \ https://api.pdfcrowd.com/convert/24.04/
import requests with open('logo.png', 'rb') as input_1: response = requests.post( 'https://api.pdfcrowd.com/convert/24.04/', auth=('demo', 'demo'), data={ 'input_format': 'image', 'output_format': 'jpg', }, files={ 'file': input_1, }, allow_redirects=False, ) response.raise_for_status() with open('logo.jpg', 'wb') as output_file: output_file.write(response.content)
import { readFile, writeFile } from 'node:fs/promises'; import { basename } from 'node:path'; const username = 'demo'; const apiKey = 'demo'; const form = new FormData(); form.append("input_format", "image"); form.append("output_format", "jpg"); form.append("file", new Blob([await readFile("logo.png")]), basename("logo.png")); const response = await fetch("https://api.pdfcrowd.com/convert/24.04/", { method: 'POST', headers: { Authorization: 'Basic ' + Buffer.from( username + ':' + apiKey).toString('base64'), }, body: form, redirect: 'manual', }); const body = Buffer.from(await response.arrayBuffer()); if (response.status >= 400) { throw new Error('HTTP ' + response.status + ' ' + response.statusText); } await writeFile("logo.jpg", body);
import axios from 'axios'; import { readFile, writeFile } from 'node:fs/promises'; import { basename } from 'node:path'; const username = 'demo'; const apiKey = 'demo'; const form = new FormData(); form.append("input_format", "image"); form.append("output_format", "jpg"); form.append("file", new Blob([await readFile("logo.png")]), basename("logo.png")); try { const response = await axios.post("https://api.pdfcrowd.com/convert/24.04/", form, { auth: { username, password: apiKey }, responseType: 'arraybuffer', maxRedirects: 0, validateStatus: status => status < 400, }); await writeFile("logo.jpg", response.data); } catch (error) { console.error(error.message); process.exitCode = 1; }
<?php require 'vendor/autoload.php'; use GuzzleHttp\Client; use GuzzleHttp\Psr7\Utils; try { $client = new Client(); $response = $client->post('https://api.pdfcrowd.com/convert/24.04/', [ 'auth' => ['demo', 'demo'], 'multipart' => [ ['name' => 'input_format', 'contents' => 'image'], ['name' => 'output_format', 'contents' => 'jpg'], ['name' => 'file', 'contents' => Utils::tryFopen('logo.png', 'rb'), 'filename' => basename('logo.png')], ], 'allow_redirects' => false, 'http_errors' => false, ]); $status = $response->getStatusCode(); if ($status >= 400) { throw new \RuntimeException("HTTP $status " . $response->getReasonPhrase()); } $body = (string) $response->getBody(); if (file_put_contents('logo.jpg', $body) !== strlen($body)) { throw new \RuntimeException('Failed to write output file'); } } catch (\Throwable $error) { fwrite(STDERR, $error->getMessage() . "\n"); exit(1); }
curl -f -s -S \ -u 'demo:demo' \ -o logo.jpg \ -F url=https://your-server.com/logo.png \ -F input_format=image \ -F output_format=jpg \ https://api.pdfcrowd.com/convert/24.04/
import requests response = requests.post( 'https://api.pdfcrowd.com/convert/24.04/', auth=('demo', 'demo'), data={ 'input_format': 'image', 'output_format': 'jpg', 'url': 'https://your-server.com/logo.png', }, allow_redirects=False, ) response.raise_for_status() with open('logo.jpg', 'wb') as output_file: output_file.write(response.content)
import { writeFile } from 'node:fs/promises'; const username = 'demo'; const apiKey = 'demo'; const form = new FormData(); form.append("input_format", "image"); form.append("output_format", "jpg"); form.append("url", "https://your-server.com/logo.png"); const response = await fetch("https://api.pdfcrowd.com/convert/24.04/", { method: 'POST', headers: { Authorization: 'Basic ' + Buffer.from( username + ':' + apiKey).toString('base64'), }, body: form, redirect: 'manual', }); const body = Buffer.from(await response.arrayBuffer()); if (response.status >= 400) { throw new Error('HTTP ' + response.status + ' ' + response.statusText); } await writeFile("logo.jpg", body);
import axios from 'axios'; import { writeFile } from 'node:fs/promises'; const username = 'demo'; const apiKey = 'demo'; const form = new FormData(); form.append("input_format", "image"); form.append("output_format", "jpg"); form.append("url", "https://your-server.com/logo.png"); try { const response = await axios.post("https://api.pdfcrowd.com/convert/24.04/", form, { auth: { username, password: apiKey }, responseType: 'arraybuffer', maxRedirects: 0, validateStatus: status => status < 400, }); await writeFile("logo.jpg", response.data); } catch (error) { console.error(error.message); process.exitCode = 1; }
<?php require 'vendor/autoload.php'; use GuzzleHttp\Client; use GuzzleHttp\Psr7\Utils; try { $client = new Client(); $response = $client->post('https://api.pdfcrowd.com/convert/24.04/', [ 'auth' => ['demo', 'demo'], 'multipart' => [ ['name' => 'input_format', 'contents' => 'image'], ['name' => 'output_format', 'contents' => 'jpg'], ['name' => 'url', 'contents' => 'https://your-server.com/logo.png'], ], 'allow_redirects' => false, 'http_errors' => false, ]); $status = $response->getStatusCode(); if ($status >= 400) { throw new \RuntimeException("HTTP $status " . $response->getReasonPhrase()); } $body = (string) $response->getBody(); if (file_put_contents('logo.jpg', $body) !== strlen($body)) { throw new \RuntimeException('Failed to write output file'); } } catch (\Throwable $error) { fwrite(STDERR, $error->getMessage() . "\n"); exit(1); }
These examples use scan.png, a 1224 × 1584 pixel image with a chart and a uniform white border. Rotation uses scan-sideways.png; JPEG background replacement uses transparent-logo.png.
Fit scan.png within 400 × 400 pixels while preserving its aspect ratio. The result is a 309 × 400 pixel thumbnail.png. Use a square canvas below when you need an exact 400 × 400 result.
curl -f -s -S \ -u 'demo:demo' \ -o thumbnail.png \ -F file=@scan.png \ -F input_format=image \ -F output_format=png \ -F resize=400x400 \ https://api.pdfcrowd.com/convert/24.04/
import requests with open('scan.png', 'rb') as input_1: response = requests.post( 'https://api.pdfcrowd.com/convert/24.04/', auth=('demo', 'demo'), data={ 'input_format': 'image', 'output_format': 'png', 'resize': '400x400', }, files={ 'file': input_1, }, allow_redirects=False, ) response.raise_for_status() with open('thumbnail.png', 'wb') as output_file: output_file.write(response.content)
import { readFile, writeFile } from 'node:fs/promises'; import { basename } from 'node:path'; const username = 'demo'; const apiKey = 'demo'; const form = new FormData(); form.append("input_format", "image"); form.append("output_format", "png"); form.append("resize", "400x400"); form.append("file", new Blob([await readFile("scan.png")]), basename("scan.png")); const response = await fetch("https://api.pdfcrowd.com/convert/24.04/", { method: 'POST', headers: { Authorization: 'Basic ' + Buffer.from( username + ':' + apiKey).toString('base64'), }, body: form, redirect: 'manual', }); const body = Buffer.from(await response.arrayBuffer()); if (response.status >= 400) { throw new Error('HTTP ' + response.status + ' ' + response.statusText); } await writeFile("thumbnail.png", body);
import axios from 'axios'; import { readFile, writeFile } from 'node:fs/promises'; import { basename } from 'node:path'; const username = 'demo'; const apiKey = 'demo'; const form = new FormData(); form.append("input_format", "image"); form.append("output_format", "png"); form.append("resize", "400x400"); form.append("file", new Blob([await readFile("scan.png")]), basename("scan.png")); try { const response = await axios.post("https://api.pdfcrowd.com/convert/24.04/", form, { auth: { username, password: apiKey }, responseType: 'arraybuffer', maxRedirects: 0, validateStatus: status => status < 400, }); await writeFile("thumbnail.png", response.data); } catch (error) { console.error(error.message); process.exitCode = 1; }
<?php require 'vendor/autoload.php'; use GuzzleHttp\Client; use GuzzleHttp\Psr7\Utils; try { $client = new Client(); $response = $client->post('https://api.pdfcrowd.com/convert/24.04/', [ 'auth' => ['demo', 'demo'], 'multipart' => [ ['name' => 'input_format', 'contents' => 'image'], ['name' => 'output_format', 'contents' => 'png'], ['name' => 'resize', 'contents' => '400x400'], ['name' => 'file', 'contents' => Utils::tryFopen('scan.png', 'rb'), 'filename' => basename('scan.png')], ], 'allow_redirects' => false, 'http_errors' => false, ]); $status = $response->getStatusCode(); if ($status >= 400) { throw new \RuntimeException("HTTP $status " . $response->getReasonPhrase()); } $body = (string) $response->getBody(); if (file_put_contents('thumbnail.png', $body) !== strlen($body)) { throw new \RuntimeException('Failed to write output file'); } } catch (\Throwable $error) { fwrite(STDERR, $error->getMessage() . "\n"); exit(1); }
Fit the whole image onto a 400 × 400 pixel canvas with either a pale blue background or transparent padding. Set 96 DPI so the px canvas dimensions match output pixels. The transparent variant preserves the original image's white background; transparency applies to the added canvas area.
Solid padding:
curl -f -s -S \ -u 'demo:demo' \ -o square.png \ -F file=@scan.png \ -F input_format=image \ -F output_format=png \ -F canvas_background_color=EEF2F6 \ -F canvas_height=400px \ -F canvas_width=400px \ -F dpi=96 \ -F print_canvas_mode=fit \ https://api.pdfcrowd.com/convert/24.04/
import requests with open('scan.png', 'rb') as input_1: response = requests.post( 'https://api.pdfcrowd.com/convert/24.04/', auth=('demo', 'demo'), data={ 'input_format': 'image', 'output_format': 'png', 'canvas_background_color': 'EEF2F6', 'canvas_height': '400px', 'canvas_width': '400px', 'dpi': '96', 'print_canvas_mode': 'fit', }, files={ 'file': input_1, }, allow_redirects=False, ) response.raise_for_status() with open('square.png', 'wb') as output_file: output_file.write(response.content)
import { readFile, writeFile } from 'node:fs/promises'; import { basename } from 'node:path'; const username = 'demo'; const apiKey = 'demo'; const form = new FormData(); form.append("input_format", "image"); form.append("output_format", "png"); form.append("canvas_background_color", "EEF2F6"); form.append("canvas_height", "400px"); form.append("canvas_width", "400px"); form.append("dpi", "96"); form.append("print_canvas_mode", "fit"); form.append("file", new Blob([await readFile("scan.png")]), basename("scan.png")); const response = await fetch("https://api.pdfcrowd.com/convert/24.04/", { method: 'POST', headers: { Authorization: 'Basic ' + Buffer.from( username + ':' + apiKey).toString('base64'), }, body: form, redirect: 'manual', }); const body = Buffer.from(await response.arrayBuffer()); if (response.status >= 400) { throw new Error('HTTP ' + response.status + ' ' + response.statusText); } await writeFile("square.png", body);
import axios from 'axios'; import { readFile, writeFile } from 'node:fs/promises'; import { basename } from 'node:path'; const username = 'demo'; const apiKey = 'demo'; const form = new FormData(); form.append("input_format", "image"); form.append("output_format", "png"); form.append("canvas_background_color", "EEF2F6"); form.append("canvas_height", "400px"); form.append("canvas_width", "400px"); form.append("dpi", "96"); form.append("print_canvas_mode", "fit"); form.append("file", new Blob([await readFile("scan.png")]), basename("scan.png")); try { const response = await axios.post("https://api.pdfcrowd.com/convert/24.04/", form, { auth: { username, password: apiKey }, responseType: 'arraybuffer', maxRedirects: 0, validateStatus: status => status < 400, }); await writeFile("square.png", response.data); } catch (error) { console.error(error.message); process.exitCode = 1; }
<?php require 'vendor/autoload.php'; use GuzzleHttp\Client; use GuzzleHttp\Psr7\Utils; try { $client = new Client(); $response = $client->post('https://api.pdfcrowd.com/convert/24.04/', [ 'auth' => ['demo', 'demo'], 'multipart' => [ ['name' => 'input_format', 'contents' => 'image'], ['name' => 'output_format', 'contents' => 'png'], ['name' => 'canvas_background_color', 'contents' => 'EEF2F6'], ['name' => 'canvas_height', 'contents' => '400px'], ['name' => 'canvas_width', 'contents' => '400px'], ['name' => 'dpi', 'contents' => '96'], ['name' => 'print_canvas_mode', 'contents' => 'fit'], ['name' => 'file', 'contents' => Utils::tryFopen('scan.png', 'rb'), 'filename' => basename('scan.png')], ], 'allow_redirects' => false, 'http_errors' => false, ]); $status = $response->getStatusCode(); if ($status >= 400) { throw new \RuntimeException("HTTP $status " . $response->getReasonPhrase()); } $body = (string) $response->getBody(); if (file_put_contents('square.png', $body) !== strlen($body)) { throw new \RuntimeException('Failed to write output file'); } } catch (\Throwable $error) { fwrite(STDERR, $error->getMessage() . "\n"); exit(1); }
Transparent padding:
curl -f -s -S \ -u 'demo:demo' \ -o square-transparent.png \ -F file=@scan.png \ -F input_format=image \ -F output_format=png \ -F canvas_background_color=00000000 \ -F canvas_height=400px \ -F canvas_width=400px \ -F dpi=96 \ -F print_canvas_mode=fit \ https://api.pdfcrowd.com/convert/24.04/
import requests with open('scan.png', 'rb') as input_1: response = requests.post( 'https://api.pdfcrowd.com/convert/24.04/', auth=('demo', 'demo'), data={ 'input_format': 'image', 'output_format': 'png', 'canvas_background_color': '00000000', 'canvas_height': '400px', 'canvas_width': '400px', 'dpi': '96', 'print_canvas_mode': 'fit', }, files={ 'file': input_1, }, allow_redirects=False, ) response.raise_for_status() with open('square-transparent.png', 'wb') as output_file: output_file.write(response.content)
import { readFile, writeFile } from 'node:fs/promises'; import { basename } from 'node:path'; const username = 'demo'; const apiKey = 'demo'; const form = new FormData(); form.append("input_format", "image"); form.append("output_format", "png"); form.append("canvas_background_color", "00000000"); form.append("canvas_height", "400px"); form.append("canvas_width", "400px"); form.append("dpi", "96"); form.append("print_canvas_mode", "fit"); form.append("file", new Blob([await readFile("scan.png")]), basename("scan.png")); const response = await fetch("https://api.pdfcrowd.com/convert/24.04/", { method: 'POST', headers: { Authorization: 'Basic ' + Buffer.from( username + ':' + apiKey).toString('base64'), }, body: form, redirect: 'manual', }); const body = Buffer.from(await response.arrayBuffer()); if (response.status >= 400) { throw new Error('HTTP ' + response.status + ' ' + response.statusText); } await writeFile("square-transparent.png", body);
import axios from 'axios'; import { readFile, writeFile } from 'node:fs/promises'; import { basename } from 'node:path'; const username = 'demo'; const apiKey = 'demo'; const form = new FormData(); form.append("input_format", "image"); form.append("output_format", "png"); form.append("canvas_background_color", "00000000"); form.append("canvas_height", "400px"); form.append("canvas_width", "400px"); form.append("dpi", "96"); form.append("print_canvas_mode", "fit"); form.append("file", new Blob([await readFile("scan.png")]), basename("scan.png")); try { const response = await axios.post("https://api.pdfcrowd.com/convert/24.04/", form, { auth: { username, password: apiKey }, responseType: 'arraybuffer', maxRedirects: 0, validateStatus: status => status < 400, }); await writeFile("square-transparent.png", response.data); } catch (error) { console.error(error.message); process.exitCode = 1; }
<?php require 'vendor/autoload.php'; use GuzzleHttp\Client; use GuzzleHttp\Psr7\Utils; try { $client = new Client(); $response = $client->post('https://api.pdfcrowd.com/convert/24.04/', [ 'auth' => ['demo', 'demo'], 'multipart' => [ ['name' => 'input_format', 'contents' => 'image'], ['name' => 'output_format', 'contents' => 'png'], ['name' => 'canvas_background_color', 'contents' => '00000000'], ['name' => 'canvas_height', 'contents' => '400px'], ['name' => 'canvas_width', 'contents' => '400px'], ['name' => 'dpi', 'contents' => '96'], ['name' => 'print_canvas_mode', 'contents' => 'fit'], ['name' => 'file', 'contents' => Utils::tryFopen('scan.png', 'rb'), 'filename' => basename('scan.png')], ], 'allow_redirects' => false, 'http_errors' => false, ]); $status = $response->getStatusCode(); if ($status >= 400) { throw new \RuntimeException("HTTP $status " . $response->getReasonPhrase()); } $body = (string) $response->getBody(); if (file_put_contents('square-transparent.png', $body) !== strlen($body)) { throw new \RuntimeException('Failed to write output file'); } } catch (\Throwable $error) { fwrite(STDERR, $error->getMessage() . "\n"); exit(1); }
Extract the chart from scan.png into chart.png, or remove the uniform outer border and save trimmed.png.
The chart starts 96 pixels from the left and 370 pixels from the top, and measures 1024 × 384 pixels. Set 96 DPI so the px crop coordinates match source image pixels. Adjust the region for your image. Automatic border removal works on solid-color borders; use an explicit crop for uneven scan edges.
Extract a selected region:
curl -f -s -S \ -u 'demo:demo' \ -o chart.png \ -F file=@scan.png \ -F input_format=image \ -F output_format=png \ -F crop_area_height=384px \ -F crop_area_width=1024px \ -F crop_area_x=96px \ -F crop_area_y=370px \ -F dpi=96 \ https://api.pdfcrowd.com/convert/24.04/
import requests with open('scan.png', 'rb') as input_1: response = requests.post( 'https://api.pdfcrowd.com/convert/24.04/', auth=('demo', 'demo'), data={ 'input_format': 'image', 'output_format': 'png', 'crop_area_height': '384px', 'crop_area_width': '1024px', 'crop_area_x': '96px', 'crop_area_y': '370px', 'dpi': '96', }, files={ 'file': input_1, }, allow_redirects=False, ) response.raise_for_status() with open('chart.png', 'wb') as output_file: output_file.write(response.content)
import { readFile, writeFile } from 'node:fs/promises'; import { basename } from 'node:path'; const username = 'demo'; const apiKey = 'demo'; const form = new FormData(); form.append("input_format", "image"); form.append("output_format", "png"); form.append("crop_area_height", "384px"); form.append("crop_area_width", "1024px"); form.append("crop_area_x", "96px"); form.append("crop_area_y", "370px"); form.append("dpi", "96"); form.append("file", new Blob([await readFile("scan.png")]), basename("scan.png")); const response = await fetch("https://api.pdfcrowd.com/convert/24.04/", { method: 'POST', headers: { Authorization: 'Basic ' + Buffer.from( username + ':' + apiKey).toString('base64'), }, body: form, redirect: 'manual', }); const body = Buffer.from(await response.arrayBuffer()); if (response.status >= 400) { throw new Error('HTTP ' + response.status + ' ' + response.statusText); } await writeFile("chart.png", body);
import axios from 'axios'; import { readFile, writeFile } from 'node:fs/promises'; import { basename } from 'node:path'; const username = 'demo'; const apiKey = 'demo'; const form = new FormData(); form.append("input_format", "image"); form.append("output_format", "png"); form.append("crop_area_height", "384px"); form.append("crop_area_width", "1024px"); form.append("crop_area_x", "96px"); form.append("crop_area_y", "370px"); form.append("dpi", "96"); form.append("file", new Blob([await readFile("scan.png")]), basename("scan.png")); try { const response = await axios.post("https://api.pdfcrowd.com/convert/24.04/", form, { auth: { username, password: apiKey }, responseType: 'arraybuffer', maxRedirects: 0, validateStatus: status => status < 400, }); await writeFile("chart.png", response.data); } catch (error) { console.error(error.message); process.exitCode = 1; }
<?php require 'vendor/autoload.php'; use GuzzleHttp\Client; use GuzzleHttp\Psr7\Utils; try { $client = new Client(); $response = $client->post('https://api.pdfcrowd.com/convert/24.04/', [ 'auth' => ['demo', 'demo'], 'multipart' => [ ['name' => 'input_format', 'contents' => 'image'], ['name' => 'output_format', 'contents' => 'png'], ['name' => 'crop_area_height', 'contents' => '384px'], ['name' => 'crop_area_width', 'contents' => '1024px'], ['name' => 'crop_area_x', 'contents' => '96px'], ['name' => 'crop_area_y', 'contents' => '370px'], ['name' => 'dpi', 'contents' => '96'], ['name' => 'file', 'contents' => Utils::tryFopen('scan.png', 'rb'), 'filename' => basename('scan.png')], ], 'allow_redirects' => false, 'http_errors' => false, ]); $status = $response->getStatusCode(); if ($status >= 400) { throw new \RuntimeException("HTTP $status " . $response->getReasonPhrase()); } $body = (string) $response->getBody(); if (file_put_contents('chart.png', $body) !== strlen($body)) { throw new \RuntimeException('Failed to write output file'); } } catch (\Throwable $error) { fwrite(STDERR, $error->getMessage() . "\n"); exit(1); }
Remove a uniform border:
curl -f -s -S \ -u 'demo:demo' \ -o trimmed.png \ -F file=@scan.png \ -F input_format=image \ -F output_format=png \ -F remove_borders=true \ https://api.pdfcrowd.com/convert/24.04/
import requests with open('scan.png', 'rb') as input_1: response = requests.post( 'https://api.pdfcrowd.com/convert/24.04/', auth=('demo', 'demo'), data={ 'input_format': 'image', 'output_format': 'png', 'remove_borders': 'true', }, files={ 'file': input_1, }, allow_redirects=False, ) response.raise_for_status() with open('trimmed.png', 'wb') as output_file: output_file.write(response.content)
import { readFile, writeFile } from 'node:fs/promises'; import { basename } from 'node:path'; const username = 'demo'; const apiKey = 'demo'; const form = new FormData(); form.append("input_format", "image"); form.append("output_format", "png"); form.append("remove_borders", "true"); form.append("file", new Blob([await readFile("scan.png")]), basename("scan.png")); const response = await fetch("https://api.pdfcrowd.com/convert/24.04/", { method: 'POST', headers: { Authorization: 'Basic ' + Buffer.from( username + ':' + apiKey).toString('base64'), }, body: form, redirect: 'manual', }); const body = Buffer.from(await response.arrayBuffer()); if (response.status >= 400) { throw new Error('HTTP ' + response.status + ' ' + response.statusText); } await writeFile("trimmed.png", body);
import axios from 'axios'; import { readFile, writeFile } from 'node:fs/promises'; import { basename } from 'node:path'; const username = 'demo'; const apiKey = 'demo'; const form = new FormData(); form.append("input_format", "image"); form.append("output_format", "png"); form.append("remove_borders", "true"); form.append("file", new Blob([await readFile("scan.png")]), basename("scan.png")); try { const response = await axios.post("https://api.pdfcrowd.com/convert/24.04/", form, { auth: { username, password: apiKey }, responseType: 'arraybuffer', maxRedirects: 0, validateStatus: status => status < 400, }); await writeFile("trimmed.png", response.data); } catch (error) { console.error(error.message); process.exitCode = 1; }
<?php require 'vendor/autoload.php'; use GuzzleHttp\Client; use GuzzleHttp\Psr7\Utils; try { $client = new Client(); $response = $client->post('https://api.pdfcrowd.com/convert/24.04/', [ 'auth' => ['demo', 'demo'], 'multipart' => [ ['name' => 'input_format', 'contents' => 'image'], ['name' => 'output_format', 'contents' => 'png'], ['name' => 'remove_borders', 'contents' => 'true'], ['name' => 'file', 'contents' => Utils::tryFopen('scan.png', 'rb'), 'filename' => basename('scan.png')], ], 'allow_redirects' => false, 'http_errors' => false, ]); $status = $response->getStatusCode(); if ($status >= 400) { throw new \RuntimeException("HTTP $status " . $response->getReasonPhrase()); } $body = (string) $response->getBody(); if (file_put_contents('trimmed.png', $body) !== strlen($body)) { throw new \RuntimeException('Failed to write output file'); } } catch (\Throwable $error) { fwrite(STDERR, $error->getMessage() . "\n"); exit(1); }
Rotate scan-sideways.png 90 degrees clockwise to restore the upright orientation, then save upright.png.
curl -f -s -S \ -u 'demo:demo' \ -o upright.png \ -F file=@scan-sideways.png \ -F input_format=image \ -F output_format=png \ -F rotate=90 \ https://api.pdfcrowd.com/convert/24.04/
import requests with open('scan-sideways.png', 'rb') as input_1: response = requests.post( 'https://api.pdfcrowd.com/convert/24.04/', auth=('demo', 'demo'), data={ 'input_format': 'image', 'output_format': 'png', 'rotate': '90', }, files={ 'file': input_1, }, allow_redirects=False, ) response.raise_for_status() with open('upright.png', 'wb') as output_file: output_file.write(response.content)
import { readFile, writeFile } from 'node:fs/promises'; import { basename } from 'node:path'; const username = 'demo'; const apiKey = 'demo'; const form = new FormData(); form.append("input_format", "image"); form.append("output_format", "png"); form.append("rotate", "90"); form.append("file", new Blob([await readFile("scan-sideways.png")]), basename("scan-sideways.png")); const response = await fetch("https://api.pdfcrowd.com/convert/24.04/", { method: 'POST', headers: { Authorization: 'Basic ' + Buffer.from( username + ':' + apiKey).toString('base64'), }, body: form, redirect: 'manual', }); const body = Buffer.from(await response.arrayBuffer()); if (response.status >= 400) { throw new Error('HTTP ' + response.status + ' ' + response.statusText); } await writeFile("upright.png", body);
import axios from 'axios'; import { readFile, writeFile } from 'node:fs/promises'; import { basename } from 'node:path'; const username = 'demo'; const apiKey = 'demo'; const form = new FormData(); form.append("input_format", "image"); form.append("output_format", "png"); form.append("rotate", "90"); form.append("file", new Blob([await readFile("scan-sideways.png")]), basename("scan-sideways.png")); try { const response = await axios.post("https://api.pdfcrowd.com/convert/24.04/", form, { auth: { username, password: apiKey }, responseType: 'arraybuffer', maxRedirects: 0, validateStatus: status => status < 400, }); await writeFile("upright.png", response.data); } catch (error) { console.error(error.message); process.exitCode = 1; }
<?php require 'vendor/autoload.php'; use GuzzleHttp\Client; use GuzzleHttp\Psr7\Utils; try { $client = new Client(); $response = $client->post('https://api.pdfcrowd.com/convert/24.04/', [ 'auth' => ['demo', 'demo'], 'multipart' => [ ['name' => 'input_format', 'contents' => 'image'], ['name' => 'output_format', 'contents' => 'png'], ['name' => 'rotate', 'contents' => '90'], ['name' => 'file', 'contents' => Utils::tryFopen('scan-sideways.png', 'rb'), 'filename' => basename('scan-sideways.png')], ], 'allow_redirects' => false, 'http_errors' => false, ]); $status = $response->getStatusCode(); if ($status >= 400) { throw new \RuntimeException("HTTP $status " . $response->getReasonPhrase()); } $body = (string) $response->getBody(); if (file_put_contents('upright.png', $body) !== strlen($body)) { throw new \RuntimeException('Failed to write output file'); } } catch (\Throwable $error) { fwrite(STDERR, $error->getMessage() . "\n"); exit(1); }
Convert transparent-logo.png to logo-background.jpg with a pale blue background. JPEG cannot retain transparency, so choose the background color explicitly.
curl -f -s -S \ -u 'demo:demo' \ -o logo-background.jpg \ -F file=@transparent-logo.png \ -F input_format=image \ -F output_format=jpg \ -F canvas_background_color=EEF2F6 \ https://api.pdfcrowd.com/convert/24.04/
import requests with open('transparent-logo.png', 'rb') as input_1: response = requests.post( 'https://api.pdfcrowd.com/convert/24.04/', auth=('demo', 'demo'), data={ 'input_format': 'image', 'output_format': 'jpg', 'canvas_background_color': 'EEF2F6', }, files={ 'file': input_1, }, allow_redirects=False, ) response.raise_for_status() with open('logo-background.jpg', 'wb') as output_file: output_file.write(response.content)
import { readFile, writeFile } from 'node:fs/promises'; import { basename } from 'node:path'; const username = 'demo'; const apiKey = 'demo'; const form = new FormData(); form.append("input_format", "image"); form.append("output_format", "jpg"); form.append("canvas_background_color", "EEF2F6"); form.append("file", new Blob([await readFile("transparent-logo.png")]), basename("transparent-logo.png")); const response = await fetch("https://api.pdfcrowd.com/convert/24.04/", { method: 'POST', headers: { Authorization: 'Basic ' + Buffer.from( username + ':' + apiKey).toString('base64'), }, body: form, redirect: 'manual', }); const body = Buffer.from(await response.arrayBuffer()); if (response.status >= 400) { throw new Error('HTTP ' + response.status + ' ' + response.statusText); } await writeFile("logo-background.jpg", body);
import axios from 'axios'; import { readFile, writeFile } from 'node:fs/promises'; import { basename } from 'node:path'; const username = 'demo'; const apiKey = 'demo'; const form = new FormData(); form.append("input_format", "image"); form.append("output_format", "jpg"); form.append("canvas_background_color", "EEF2F6"); form.append("file", new Blob([await readFile("transparent-logo.png")]), basename("transparent-logo.png")); try { const response = await axios.post("https://api.pdfcrowd.com/convert/24.04/", form, { auth: { username, password: apiKey }, responseType: 'arraybuffer', maxRedirects: 0, validateStatus: status => status < 400, }); await writeFile("logo-background.jpg", response.data); } catch (error) { console.error(error.message); process.exitCode = 1; }
<?php require 'vendor/autoload.php'; use GuzzleHttp\Client; use GuzzleHttp\Psr7\Utils; try { $client = new Client(); $response = $client->post('https://api.pdfcrowd.com/convert/24.04/', [ 'auth' => ['demo', 'demo'], 'multipart' => [ ['name' => 'input_format', 'contents' => 'image'], ['name' => 'output_format', 'contents' => 'jpg'], ['name' => 'canvas_background_color', 'contents' => 'EEF2F6'], ['name' => 'file', 'contents' => Utils::tryFopen('transparent-logo.png', 'rb'), 'filename' => basename('transparent-logo.png')], ], 'allow_redirects' => false, 'http_errors' => false, ]); $status = $response->getStatusCode(); if ($status >= 400) { throw new \RuntimeException("HTTP $status " . $response->getReasonPhrase()); } $body = (string) $response->getBody(); if (file_put_contents('logo-background.jpg', $body) !== strlen($body)) { throw new \RuntimeException('Failed to write output file'); } } catch (\Throwable $error) { fwrite(STDERR, $error->getMessage() . "\n"); exit(1); }
Convert scan.png to scan.webp at its original pixel dimensions. WebP uses lossy compression here, which can reduce file size at the cost of fine detail. Compare the result with your source image before choosing it for web delivery.
curl -f -s -S \ -u 'demo:demo' \ -o scan.webp \ -F file=@scan.png \ -F input_format=image \ -F output_format=webp \ https://api.pdfcrowd.com/convert/24.04/
import requests with open('scan.png', 'rb') as input_1: response = requests.post( 'https://api.pdfcrowd.com/convert/24.04/', auth=('demo', 'demo'), data={ 'input_format': 'image', 'output_format': 'webp', }, files={ 'file': input_1, }, allow_redirects=False, ) response.raise_for_status() with open('scan.webp', 'wb') as output_file: output_file.write(response.content)
import { readFile, writeFile } from 'node:fs/promises'; import { basename } from 'node:path'; const username = 'demo'; const apiKey = 'demo'; const form = new FormData(); form.append("input_format", "image"); form.append("output_format", "webp"); form.append("file", new Blob([await readFile("scan.png")]), basename("scan.png")); const response = await fetch("https://api.pdfcrowd.com/convert/24.04/", { method: 'POST', headers: { Authorization: 'Basic ' + Buffer.from( username + ':' + apiKey).toString('base64'), }, body: form, redirect: 'manual', }); const body = Buffer.from(await response.arrayBuffer()); if (response.status >= 400) { throw new Error('HTTP ' + response.status + ' ' + response.statusText); } await writeFile("scan.webp", body);
import axios from 'axios'; import { readFile, writeFile } from 'node:fs/promises'; import { basename } from 'node:path'; const username = 'demo'; const apiKey = 'demo'; const form = new FormData(); form.append("input_format", "image"); form.append("output_format", "webp"); form.append("file", new Blob([await readFile("scan.png")]), basename("scan.png")); try { const response = await axios.post("https://api.pdfcrowd.com/convert/24.04/", form, { auth: { username, password: apiKey }, responseType: 'arraybuffer', maxRedirects: 0, validateStatus: status => status < 400, }); await writeFile("scan.webp", response.data); } catch (error) { console.error(error.message); process.exitCode = 1; }
<?php require 'vendor/autoload.php'; use GuzzleHttp\Client; use GuzzleHttp\Psr7\Utils; try { $client = new Client(); $response = $client->post('https://api.pdfcrowd.com/convert/24.04/', [ 'auth' => ['demo', 'demo'], 'multipart' => [ ['name' => 'input_format', 'contents' => 'image'], ['name' => 'output_format', 'contents' => 'webp'], ['name' => 'file', 'contents' => Utils::tryFopen('scan.png', 'rb'), 'filename' => basename('scan.png')], ], 'allow_redirects' => false, 'http_errors' => false, ]); $status = $response->getStatusCode(); if ($status >= 400) { throw new \RuntimeException("HTTP $status " . $response->getReasonPhrase()); } $body = (string) $response->getBody(); if (file_put_contents('scan.webp', $body) !== strlen($body)) { throw new \RuntimeException('Failed to write output file'); } } catch (\Throwable $error) { fwrite(STDERR, $error->getMessage() . "\n"); exit(1); }