Hi, I'm Christoph, the developer of compress-or-die.com.
I hereby ask you to accept the cookies
of the self-hosted Matomo Tracking software which I use to analyze the traffic to this website.
You can revoke your consent at any time on the following page: Privacy policy.
Since COD was developed with the background in mind that each image is different and therefore needs to be checked individually to get the best possible result, the API is a little different.
You'll send your image to the API and get a session ID back, with which you can then call the page "compress-or-die.com" in your browser with your image presented in the well-known GUI.
Here are some examples how to integrate COD into your scripts.
If you are a PHP developer the following CLI script could be useful. Use it like this:
$ php compress-or-die.com.php your-image.png
PHP has to be in your OS environment variable PATH and you need to have the CURL extension installed.
Works on Windows and MacOSX.
compress-or-die.php
<?php
define('FOR_VERSION', 2);
// set the host (use for debugging)
$host = 'http://compress-or-die.com';
// get filename passed to the script
$filename = $argv[count($argv) - 1];
// send file to the API
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $host . '/api-v2');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
// this is the filename that is offered to you on download'X-DOCUMENT-NAME: ' . basename($filename)
]);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, file_get_contents($filename));
$body = curl_exec($ch);
curl_close ($ch);
// parse the answer to get the session id
$answer = [];
foreach(explode("\n", trim($body)) as $line) {
$parts = explode(':', $line, 2);
$answer[$parts[0]] = $parts[1];
}
// check versionif ($answer['_VERSION'] != FOR_VERSION) {
fwrite(STDERR, 'Aborting: This script is for version ' . FOR_VERSION . ', but the current version is ' . $answer['_VERSION'] . '.');
exit(1);
}
// open the browser to show the image on compress-or-die.com
$command = stripos(getenv('OS'), 'Windows') !== false ? 'start'/* Windows */ : 'open'/* Mac */;
shell_exec($command . ' ' . $host . '/' . $answer['_URL'] . '?session=' . $answer['_SESSION']);
If you are a Javascript developer the following example script could be useful.
Just copy the example to a file "index.htm" and open it in the browser.
index.htm
<!DOCTYPE html><html><head><title>JS Demo</title></head><body><inputtype="file"name="file"id="file" /><script>document.querySelector('#file').addEventListener('change', (e) => {
const files = e.target.files
if (files.length) {
processFile(files[0])
}
})
functionprocessFile(file) {
const FOR_VERSION = 2// get filename passed to the scriptvar filename = file.name
// send file to the API
fetch('https://compress-or-die.com/api-v2', {
method: 'POST',
headers: {
// this is the filename that is offered to you on download'X-DOCUMENT-NAME': filename,
},
body: file
})
.then(response => response.text())
.then(response => {
// parse the answer to get the session idconst answer = {}
response.split("\n").forEach(el => {
let [key, ...value] = el.split(':');
value = value.join(':');
answer[key] = value
})
// check versionif (answer._VERSION != FOR_VERSION) {
thrownewError(`Aborting: This script is for version ${FOR_VERSION}, but the current version is ${answer._VERSION}.`)
} else {
// open the browser to show the image on compress-or-die.com
location.href = `${answer._URL}?session=${answer._SESSION}`
}
})
}
</script></body></html>
If you are a Node.js developer the following CLI script could be useful. Use it like this:
$ node compress-or-die.com.js your-image.png
First you have to install some node modules:
$ npm install request opn
Works on Windows, MacOSX and Linux.
compress-or-die.js
var request = require('request');
var fs = require('fs');
var path = require('path');
var opn = require('opn');
const FOR_VERSION = 2;
// get filename passed to the scriptvar filename = process.argv[process.argv.length - 1];
// send file to the API
request.post({
url: 'http://compress-or-die.com/api-v2',
headers: {
// this is the filename that is offered to you on download'X-DOCUMENT-NAME' : path.basename(filename)
},
body: fs.createReadStream(filename)
}, function(error, response, body){
// parse the answer to get the session idvar answer = {};
body.split("\n").forEach(el => {
let [key, ...value] = el.split(':');
value = value.join(':');
answer[key] = value
});
// check versionif (answer._VERSION != FOR_VERSION) {
process.stderr.write('Aborting: This script is for version ' + FOR_VERSION + ', but the current version is ' + answer._VERSION + '.');
process.exit(1);
}
// open the browser to show the image on compress-or-die.com
opn(answer._URL + '?session=' + answer._SESSION);
});
If you are a Python developer the following CLI script could be useful. Use it like this:
$ py compress-or-die.com.py your-image.png
First you have to install a module:
$ pip install requests
Works on Windows and MacOSX.
compress-or-die.py
import sys, os, requests
from sys import platform
from subprocess import call
FOR_VERSION = 2# get filename passed to the script
filename = sys.argv[-1];
# send file to the APIwith open(filename, 'rb') as f:
response = requests.post('http://compress-or-die.com/api-v2', data=f, headers={'X-DOCUMENT-NAME': os.path.basename(filename)})
# parse the answer to get the session id
lines = response.text.splitlines()
answer = {}
for line in lines:
parts = line.split(':', 1);
answer[parts[0]] = parts[1]
# check versionif (int(answer['_VERSION']) != FOR_VERSION):
print('Aborting: This script is for version ' + str(FOR_VERSION) + ', but the current version is ' + answer['_VERSION'] + '.', file=sys.stderr)
exit(1)
# open the browser to show the image on compress-or-die.comfrom sys import platform
if platform == "darwin":
call(['open', answer['_URL'] + '?session=' + answer['_SESSION']])
elif platform == "win32":
call(['cmd.exe', '/c', 'start', answer['_URL'] + '?session=' + answer['_SESSION']])
You don't like ads? Support Compress-Or-Die and become a patron who does not see ads. Your upload limit gets doubled too!
News
COD says Goodbye
2026-06-24
After 10 years of compress-or-die.com, it’s time for me to say goodbye. It’s been a great time—I’ve learned a lot technically, but I’ve also met some wonderful people.
compress-or-die.com was created back then to get the most out of graphics for small banners. At the time, I was still working at an advertising agency. And over time, it just kept growing and growing.
But some of you may have noticed that over the past two years, there have been hardly any changes, and there hasn’t been much from me to read—which was quite different back in the day.
But a lot has changed in my personal life: children, new and different hobbies, and health issues have shifted my focus in other directions. And so, I had less and less time and motivation left for this project that was once so close to my heart.
For this reason, this chapter is now coming to an end. I’d like to thank all of you for using COD and for providing such great feedback, which helped COD grow so much.
I’d especially like to thank the Patrons who have covered the server costs over the past few years. Thank you so much!
On July 25, 2026, I will send COD into its well-deserved retirement.
All the best to you all,
Christoph
Check out our Reddit channel if you want to comment on the news.