Giter Site home page Giter Site logo

ekowtaylor / image-resize-api Goto Github PK

View Code? Open in Web Editor NEW

This project forked from falconshark/image-resize-api

0.0 0.0 0.0 35 KB

A simple Web API for resize image easily.

Home Page: https://resize.sardo.work

License: MIT License

JavaScript 8.14% PHP 91.86%

image-resize-api's Introduction

Image Resize API

Simple Web API for resize image easily.

Powered by php-image-resize library.

API URL

https://resize.sardo.work

Function

Currently, it will only resize image best to fit. Maybe add more function in the future.

Installation

You can host this file on your Web server. Support PHP 5.6 or PHP 7.

Install the dependencies:

$ composer install

Parameter

All of the paramter is required, otherwise server will return error message.

ImageUrl

The url of image. Accept png, jpg, gif, and webp, and the file which not larger than 500MB.

Width

The width of resized image. Must be integer.

Height

The height of resized image. Must be integer.

Quality

The quality of resized image.

Must be an integer ranging from 0 to 100 :

  • 0 = no compression.
  • 1 = worst quality, smaller file.
  • 100 = best quality, biggest file.
  • default value is 85

This only applies to JPG/JPEG and WEBP image files.

Usage

You can call the API to resize image with post method. Currently it only accept remote image.

Get cropped image by GET method:

You can just use the this url to crop the image. This method will return an cropped image directly, not JSON result.

https://resize.sardo.work/?imageUrl={image_url}&width={image_width}&height={image_height}&quality={image_quality}

Get cropped image by POST method:

fetch('https://apiserver.com', {
  body:JSON.stringify({
    width: 500,
    height: 300,
    quality: 50,
    imageUrl: 'http://example.com/image.png',
  }),
  headers: {
    'content-type': 'application/json',
  },
  method: 'POST',
})
.then(response => response.json())
.then((result) =>{
  console.log(result);
});

If everything is OK, it will return a JSON which contain status and cropped image data (Data url of resized image):

{ status: 'Success',
  filename: 'image-filename.jpg',
  cropped_image_data:
   '/9j/4AAQSkZJRgABAQAAAQABAAD//gA7Q1JFQVRPUjogZ2QtanBlZyB2MS4wICh1c2luZyBJSkcgSlBFRyB2OTApLCBxdWFsaXR5ID0gODUK/9sAQwAFAwQEBAMFBAQEBQUFBgcMCAcHBwcPCwsJDBEPEhIRDxERExYcFxMUGhURERghGBodHR8fHxMXIiQiHiQcHh8e/9sAQwEFBQUHBgcOCAgOHhQRFB4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4e/8IAEQgBLAHWAwEiAAIRAQMRAf/EABwAAAEFAQEBAAAAAAAAAAAAAAIAAQQFBgMHCP/EABkBAQEBAQEBAAAAAAAAAAAAAAABAgMEB...' }

The API will not keep your image.

Otherwise it will return a json which contain error message. For example:

{ status: 'Failed',
  error_message: 'Please provide the url of image.'}

Frontend Test

You can test the api function without browser, there are a pre-ready script at frontend-test folder. It requires Node.js (Recommanded to use v10.x.x Version) to run.

Before use the script, install the dependencies by npm, then copy the config file:

cd frontend-test
npm install
cp config.example.json config.json

Edit the config file:

{
  "serverUrl": "Your api server url",
  "imageUrl": "Image for testing",
}

Then you can run it now.

node upload.js

Issues

If there are any bug, or request new function, please feel feel to open an issues or pull request.

image-resize-api's People

Contributors

falconshark avatar sekedus avatar dependabot[bot] avatar bhedouin avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.