API Documentation

Getting Started

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.


How to use

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.


Our Clients

You can use HTTP or PHP client. Other clients are coming soon. You can create your own client by following HTTP client reference.


HTTP Request Paramaters

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:

  • scale - Scales the image down proportionally. You must provide either a target width or a target height, but not both. The scaled image will have exactly the provided width or height.
  • fit - Scales the image down proportionally so that it fits within the given dimensions. You must provide both a width and a height. The scaled image will not exceed either of these dimensions. fit[:hexedecimalColor] is valid as well. You can define hexedecimal backround color like fit:#ededed
  • cover - Scales the image proportionally and crops it if necessary so that the result has exactly the given dimensions. You must provide both a width and a height. Which parts of the image are cropped away is determined automatically. An intelligent algorithm determines the most important areas and leaves these intact.


HTTP JSON Response

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"
}                                   
                                   


HTTP Request With URL

Request

//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
                                    
Response

{  
   "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"
}