You need to Sign Up for Jpegify API services and obtain your unique API Key and API Secret. You will find those in your Account under the API Credentials section. Once you have set-up your Account, you can start using Jpegify API in your applications.
You can optimize your images in three ways - by providing an URL of the image you want to optimize,
by uploading binary image data and by uploading an image file directly to Jpegify API.
The first option (image URL) is great for images that are already in production or any other place
on the Internet. The second one (binary image uploading) is ideal if you have binary image data
during code execution. The third one (direct upload) is ideal for your deployment process, build
script or the on-the-fly processing of your user's uploads where you don't have the images available online yet.
You can use HTTP or PHP client. Other clients are coming soon. You can create your own client by following HTTP client reference.
All HTTP requests must be in JSON formated. Full request pattern is below:
{
"auth": { //mandatory
"api_key": "your-api-key", //mandatory
"api_secret": "your-api-secret" //mandatory
},
"url":"", // must be a valid url. "file" and "base64" must be empty.
"file":"", // must be a valid local file path. "url" and "base64" must be empty.
"base64":"", // must be a base64 encoded image data. "url" and "file" must be empty.
"callback_url":"", // this is for the feature. must be null.
"resize":{ //optional. use if you want to resize than after optimzie
"width":"", //optional. resizing with must be filled or emtpy according to strategy
"height":"", //optional. resizing with must be filled or emtpy according to strategy
"strategy":"" //optional but mondotary if resize activated.
},
"sandbox":true //optional. send 1 if you want to work on sandbox mode
}
You can use just url, file or base64 at a time.
One of them is mondatory. callback_url paramater is reserved for the
future usage. resize paramater is optional.
The strategy property can have one of the following values:
All HTTP requests must be in JSON formated. Full request pattern is below:
{
"success": true,
"file_name": "file.jpg",
"original_size": 518997,
"new_size": 24423,
"original_width": 1200,
"original_height": 1800,
"download_url": "https://c.jpegify.com/api/w/8/file.jpg"
}
//endpoint: https://jpegify.com//api/v1/fromurl
curl \
--header "Content-type: application/json" \
--request POST \
--data-binary '{"auth": {"api_key": "your-api-key","api_secret": "your-api-secret"},"url":"https://your-image-url","callback_url":""}' \
https://jpegify.com//api/v1/fromurl
{
"success":true,
"file_name":"abcd.jpg",
"original_size":38621,
"new_size":15035,
"original_width":414,
"original_height":622,
"download_url":"https:\/\/c.jpegify.com\/api\/abcd.jpg",
"saved_bytes":23586,
"saved_percent":"61.07"
}