How Can We Help You?

Cropping

You can crop an image to remove unnecessary elements or extract a piece of the image that contains the most interesting parts. The Picsmize Image API allows you to crop images in three different ways: rect, ratio, and face.

Rect

You can use this mode to extract a rectangular section of an image by specifying the width and height of the fragment you want to extract, as well as a gravity parameter if desired. Crop gravity is set to center by default, but you can change it to top-left, top, top-right, right, bottom-right, bottom, bottom-left, or left.

<?php

/**
* Instantiate new `$picsmize` by calling a constructor
*/

$picsmize = new Picsmize('your-api-key');

/**
* Provide a publicly available image URL with fetch(string) method,
* and extract a 375 x 150 portion of the image at center position
*/

$picsmize
->fetch('https://www.example.com/image.jpg')
->resize(Picsmize::CROP_RECT, array(
'width' => 375,
'height' => 150,
'gravity' => "center"
))
->toJSON(function ($response) {
if ($response['status'] == false) {
throw new Exception($response);
}

/**
* You'll find the full JSON metadata array within the `$response` variable.
* Remember to always check if the `status` property is set to `true`.
*/

if ($response['status'] == true) {
print ($response['output']['src']);
} else {
print ($response['message']);
}
});
curl -X POST \
https://api.picsmize.com/image/process \
-H "apikey: your-api-key" \
-H "content-type: application/json" \
-d '{
"img_url": "https://www.example.com/image.jpg",
"process": {
"crop": {
"mode": "rect",
"width": 375,
"height": 150,
"gravity": "center"
}
}
}'
									
										package main

										import (
											"fmt"

											"github.com/picsmize/picsmize-go"
										)

										func main() {

											pics, err := picsmize.Init("your-api-key")
											if err != nil {
												panic(err)
											}

											/**
											* Provide a publicly available image URL with fetch(string) method,
											* and extract a 375 x 150 portion of the image at center position
											*/

											res, err := pics.Fetch("your-image-url").
												Crop("rect", picsmize.Options{
													"width": 375,
													"height": 150,
													"gravity": "center",
												}).
												ToJSON()

											if err != nil {
												panic(err)
											}

											/**
											* You'll find the full JSON metadata within the `res` variable.
											*/

											fmt.Println(res)
										}
									
								
Given the input image 750px × 300px
Resizing An Image Online
Extract the default center portion of the image by setting "width" to 375 and "height" to 150
Compressor Photo
The resulting image is 375px × 150px cropped from the center
Image Online Resize

You can skip the gravity parameter and specify x and y coordinates if you know the exact position of the fragment you want to remove. The origin (zero point) lies in the top-left corner of the image.

<?php

/**
* Instantiate new `$picsmize` by calling a constructor
*/

$picsmize = new Picsmize('your-api-key');

/**
* Provide a publicly available image URL with fetch(string) method,
* and extract a 375 x 150 portion of the image at x=270 and y=80 position
*/

$picsmize
->fetch('https://www.example.com/image.jpg')
->resize(Picsmize::CROP_RECT, array(
'width' => 375,
'height' => 150,
'x' => 270,
'y' => 80
))
->toJSON(function ($response) {
if ($response['status'] == false) {
throw new Exception($response);
}

/**
* You'll find the full JSON metadata array within the `$response` variable.
* Remember to always check if the `status` property is set to `true`.
*/

if ($response['status'] == true) {
print ($response['output']['src']);
} else {
print ($response['message']);
}
});
curl -X POST \
https://api.picsmize.com/image/process \
-H "apikey: your-api-key" \
-H "content-type: application/json" \
-d '{
"img_url": "https://www.example.com/image.jpg",
"process": {
"crop": {
"mode": "rect",
"width": 375,
"height": 150,
"x": 270,
"y": 80
}
}
}'
									
										package main

										import (
											"fmt"

											"github.com/picsmize/picsmize-go"
										)

										func main() {

											pics, err := picsmize.Init("your-api-key")
											if err != nil {
												panic(err)
											}

											/**
											* Provide a publicly available image URL with fetch(string) method,
											* and extract a 375 x 150 portion of the image at x=270 and y=80 position
											*/

											res, err := pics.Fetch("your-image-url").
												Crop("rect", picsmize.Options{
													"width": 375,
													"height": 150,
													"x": 270,
													"y": 80,
												}).
												ToJSON()

											if err != nil {
												panic(err)
											}

											/**
											* You'll find the full JSON metadata within the `res` variable.
											*/

											fmt.Println(res)
										}
									
								
Given the input image 750px × 300px
Compress Jpeg
Extract the portion of the image at x=270, y=80 by setting "width" to 375 and "height" to 150
Compressing An Image
The resulting image is 375px × 150px cropped at x=270, y=80
Compress The Photo
Ratio

You can set the aspect ratio of the generated image in this mode. The Picsmize API will determine width and height for you based on the ratio parameter you supply.

You can also specify a gravity parameter in addition to the ratio cropping. Crop gravity is set to centre by default, but you can change it to top-left, top, top-right, right, bottom-right, bottom , bottom-left, or left.

Simply set mode to ratio within the crop hash and supply the required aspect ratio string as a value for the ratio key to employ ratio cropping:

<?php

/**
* Instantiate new `$picsmize` by calling a constructor
*/

$picsmize = new Picsmize('your-api-key');

/**
* Provide a publicly available image URL with fetch(string) method,
* set crop mode to "ratio" and passing "5:9" ration string as a value for the ratio key
*/

$picsmize
->fetch('https://www.example.com/image.jpg')
->crop(Picsmize::CROP_RATIO, array(
'ratio' => "5:9"
))
->toJSON(function ($response) {
if ($response['status'] == false) {
throw new Exception($response);
}

/**
* You'll find the full JSON metadata array within the `$response` variable.
* Remember to always check if the `status` property is set to `true`.
*/

if ($response['status'] == true) {
print ($response['output']['src']);
} else {
print ($response['message']);
}
});
curl -X POST \
https://api.picsmize.com/image/process \
-H "apikey: your-api-key" \
-H "content-type: application/json" \
-d '{
"img_url": "https://www.example.com/image.jpg",
"process": {
"crop": {
"mode": "ratio",
"ratio": "5:9"
}
}
}'
									
										package main

										import (
											"fmt"

											"github.com/picsmize/picsmize-go"
										)

										func main() {

											pics, err := picsmize.Init("your-api-key")
											if err != nil {
												panic(err)
											}

											/**
											* Provide a publicly available image URL with fetch(string) method,
											* set crop mode to "ratio" and passing "5:9" ration string as a value for the ratio key
											*/

											res, err := pics.Fetch("your-image-url").
												Crop("ratio", picsmize.Options{
													"ratio": "5:9",
												}).
												ToJSON()

											if err != nil {
												panic(err)
											}

											/**
											* You'll find the full JSON metadata within the `res` variable.
											*/

											fmt.Println(res)
										}
									
								
Given the input image 750px × 300px
Images Size Reducer
Crop the image using aspect ratio of "5:9"
Resizing Of Image

A 1:1 aspect ratio will result in a square image, which is ideal for social media and grid layouts:

Resizing An Image Online

By adding an extra gravity parameter, you can have even more control over aspect ratio cropping. For example, if the crop ratio is set to 4:3 and gravity is set to left, the outcome will be as follows:

<?php

/**
* Instantiate new `$picsmize` by calling a constructor
*/

$picsmize = new Picsmize('your-api-key');

/**
* Provide a publicly available image URL with fetch(string) method,
* set crop mode to "ratio" and passing "4:3" ration string as a value for the ratio key,
* gravity set to "left"
*/

$picsmize
->fetch('https://www.example.com/image.jpg')
->crop(Picsmize::CROP_RATIO, array(
'ratio' => "4:3",
'gravity' => "left"
))
->toJSON(function ($response) {
if ($response['status'] == false) {
throw new Exception($response);
}

/**
* You'll find the full JSON metadata array within the `$response` variable.
* Remember to always check if the `status` property is set to `true`.
*/

if ($response['status'] == true) {
print ($response['output']['src']);
} else {
print ($response['message']);
}
});
curl -X POST \
https://api.picsmize.com/image/process \
-H "apikey: your-api-key" \
-H "content-type: application/json" \
-d '{
"img_url": "https://www.example.com/image.jpg",
"process": {
"crop": {
"mode": "ratio",
"ratio": "4:3",
"gravity": "left"
}
}
}'
									
										package main

										import (
											"fmt"

											"github.com/picsmize/picsmize-go"
										)

										func main() {

											pics, err := picsmize.Init("your-api-key")
											if err != nil {
												panic(err)
											}

											/**
											* Provide a publicly available image URL with fetch(string) method,
											* set crop mode to "ratio" and passing "4:3" ration string as a value for the ratio key,
											* gravity set to "left"
											*/

											res, err := pics.Fetch("your-image-url").
												Crop("ratio", picsmize.Options{
													"ratio": "4:3",
													"gravity": "left"
												}).
												ToJSON()

											if err != nil {
												panic(err)
											}

											/**
											* You'll find the full JSON metadata within the `res` variable.
											*/

											fmt.Println(res)
										}
									
								
Resizing Pictures
Face

Face detection techniques can be used in face mode to quickly extract the section of the image that contains a face. A padding parameter, which accepts an integer and indicates the distance between the face and image limits, can be specified. The more padding there is, the more space around the face will be shown in the final image.

Let's look at an example of a simple use-case. Let's say you want to do a face crop and give the face a padding of 100px such that the face and image limits are separated by exactly 100 pixels in each direction.

<?php

/**
* Instantiate new `$picsmize` by calling a constructor
*/

$picsmize = new Picsmize('your-api-key');

/**
* Provide a publicly available image URL with fetch(string) method,
* set crop mode to "face",
* padding set to "100"
*/

$picsmize
->fetch('https://www.example.com/image.jpg')
->crop(Picsmize::CROP_FACE, array(
'padding' => 100
))
->toJSON(function ($response) {
if ($response['status'] == false) {
throw new Exception($response);
}

/**
* You'll find the full JSON metadata array within the `$response` variable.
* Remember to always check if the `status` property is set to `true`.
*/

if ($response['status'] == true) {
print ($response['output']['src']);
} else {
print ($response['message']);
}
});
curl -X POST \
https://api.picsmize.com/image/process \
-H "apikey: your-api-key" \
-H "content-type: application/json" \
-d '{
"img_url": "https://www.example.com/image.jpg",
"process": {
"crop": {
"mode": "face",
"padding": 100
}
}
}'
									
										package main

										import (
											"fmt"

											"github.com/picsmize/picsmize-go"
										)

										func main() {

											pics, err := picsmize.Init("your-api-key")
											if err != nil {
												panic(err)
											}

											/**
											* Provide a publicly available image URL with fetch(string) method,
											* set crop mode to "face",
											* padding set to "100"
											*/

											res, err := pics.Fetch("your-image-url").
												Crop("face", picsmize.Options{
													"padding": 100,
												}).
												ToJSON()

											if err != nil {
												panic(err)
											}

											/**
											* You'll find the full JSON metadata within the `res` variable.
											*/

											fmt.Println(res)
										}
									
								
Given the input image 750px × 400px
Compress A Png
Extract the portion of the image which contains a face and ensure 100px between the face and image bounds
Compressor Photo

When more than one face is discovered, the API will extract the section of the image that contains all of the faces by default. Using the same settings as before, set the "mode": "face" and the "padding": 100. When you supply an image with multiple faces, with the same setting, you'll get the following output:

Given the input image 750px × 400px
Compress Jpeg
Extract the portion of the image which contains a face and ensure 100px between the face and image bounds
Compressing An Image

If the image has more than one face, the API will ensure that the extracted portion of the image contains all of the faces by default. You can change this behavior by passing a number to the index argument, which specifies which face to extract. If no faces are found, the API will either return the input image or send it on to the next transformation step you requested.

<?php

/**
* Instantiate new `$picsmize` by calling a constructor
*/

$picsmize = new Picsmize('your-api-key');

/**
* Provide a publicly available image URL with fetch(string) method,
* set crop mode to "face",
* index set to "1" and padding to "100"
*/

$picsmize
->fetch('https://www.example.com/image.jpg')
->crop(Picsmize::CROP_FACE, array(
'index' => 1,
'padding' => 100
))
->toJSON(function ($response) {
if ($response['status'] == false) {
throw new Exception($response);
}

/**
* You'll find the full JSON metadata array within the `$response` variable.
* Remember to always check if the `status` property is set to `true`.
*/

if ($response['status'] == true) {
print ($response['output']['src']);
} else {
print ($response['message']);
}
});
curl -X POST \
https://api.picsmize.com/image/process \
-H "apikey: your-api-key" \
-H "content-type: application/json" \
-d '{
"img_url": "https://www.example.com/image.jpg",
"process": {
"crop": {
"mode": "face",
"index": 1,
"padding": 100,
}
}
}'
									
										package main

										import (
											"fmt"

											"github.com/picsmize/picsmize-go"
										)

										func main() {

											pics, err := picsmize.Init("your-api-key")
											if err != nil {
												panic(err)
											}

											/**
											* Provide a publicly available image URL with fetch(string) method,
											* set crop mode to "face",
											* index set to "1" and padding to "100"
											*/

											res, err := pics.Fetch("your-image-url").
												Crop("face", picsmize.Options{
													"index": 1
													"padding": 100,
												}).
												ToJSON()

											if err != nil {
												panic(err)
											}

											/**
											* You'll find the full JSON metadata within the `res` variable.
											*/

											fmt.Println(res)
										}
									
								
Given the input image 750px × 400px
Compress The Photo
Extract the portion of the image which contains a face on the left and ensure 100px between the face and image bounds
Resizing Of Image

You can select the face you want to extract by setting an index parameter. Faces are numbered starting from 1, from left to right, thus if you want to extract the face on the right, you'll need to set 2 as the index value. Like set "index": 2

Given the input image 750px × 400px
Images Size Reducer
Extract the portion of the image which contains a face on the right and ensure 100px between the face and image bounds
Compress Jpeg