<?php $url = 'http://server.com/image.jpg'; $data = json_decode(file_get_contents('http://api.rest7.com/v1/jpeg_optim.php?url=' . $url . '&encoding=baseline')); if (@$data->success !== 1) { die('Failed'); } $image = file_get_contents($data->file); file_put_contents('clean.jpg', $image);