How Can We Help You?

Resizing

The single most essential operation that can be performed on an image is image resizing. The Picsmize Image API gives you the option of selecting a resizing mode for various instances. In most circumstances, the API will do all of the computations for you when it comes to the image's aspect ratio. The Picsmize API provides a full description of all scaling modes available. Below, you will find the Picsmize API’s full description of various resizing modes : Auto, Fit, Fill and Exact


Auto

Even if the mode parameter is not given, auto is the default mode for image resizing. It takes width and/or height as attributes. This option will always resize an image by its aspect ratio, thus if you simply give the width attribute, the height will be altered as well.

When both the width and height attributes are given, the image will be adjusted so that it does not exceed the set dimensions.

In other words:

I want the image to be at maximum width and height, or

I want the image's width to be at 400 and height to be changed automatically for me, or

I want the image's height to be at 100 and width to be automatically adjusted for me.

<?php

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

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

/**
* Provide a publicly available image URL with fetch(string) method,
* resize the image to 400 x 300, set resize mode to "auto"
*/

$picsmize
->fetch('https://www.example.com/image.jpg')
->resize(Picsmize::RESIZE_AUTO, array(
'width' => 400,
'height' => 300,
))
->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": {
"resize": {
"mode": "auto",
"width": 400,
"height": 300
}
}
}'
									
										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,
											* resize the image to 400 x 300, set resize mode to "auto"
											*/

											res, err := pics.Fetch("your-image-url").
												Resize("auto", picsmize.Options{
													"width":  400,
													"height": 300,
												}).
												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 Jpeg
Resize it with "auto" mode setting "width" to 300px
Compressing An Image
The resulting image is 300px × 160px
Fit

This mode expects both width and height parameters and resizes the image to meet the supplied dimensions using the aspect ratio, ensuring that the image completely covers the region described by the dimensions. Smaller images will be upscaled proportionally to fit into the output frame size. Any particularly noteworthy sections of the image will be edited out. The default crop gravity value is center, but you can change it to top,bottom,right or left by providing one of the following: top,bottom,right or left.

Picsmize allows face and faces as gravity values in addition to direction-based gravity, and will use face-detection algorithms to place any discovered faces in the center of the enlarged image. The API will revert to the default center gravity if no faces are identified. Face gravity centers the image on the largest (typically most prominent) face identified in the image, whereas faces focus the image on all of the faces - see samples below.

<?php

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

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

/**
* Provide a publicly available image URL with fetch(string) method,
* resize the image to 200 x 200, set resize mode to "fit",
* and gravity set to "right"
*/

$picsmize
->fetch('https://www.example.com/image.jpg')
->resize(Picsmize::RESIZE_FIT, array(
'width' => 200,
'height' => 200,
'gravity' => "right"
))
->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": {
"resize": {
"mode": "fit",
"width": 200,
"height": 200,
"gravity": "right"
}
}
}'
									
										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,
											* resize the image to 200 x 200, set resize mode to "fit",
											* and gravity set to "right"
											*/

											res, err := pics.Fetch("your-image-url").
												Resize("fit", picsmize.Options{
													"width":  200,
													"height": 200,
													"gravity": "right",
												}).
												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
Resize it with "fit" mode setting "width" to 200px, "height" to 200px and crop gravity to "right"
Images Size Reducer
The resulting image is 200px × 200px cropped from the right direction

Simply use the face as a gravity value to center the image on a single, prominent face:

<?php

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

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

/**
* Provide a publicly available image URL with fetch(string) method,
* resize the image to 250 x 200, set resize mode to "fit",
* and gravity set to "face"
*/

$picsmize
->fetch('https://www.example.com/image.jpg')
->resize(Picsmize::RESIZE_FIT, array(
'width' => 250,
'height' => 200,
'gravity' => "face"
))
->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": {
"resize": {
"mode": "fit",
"width": 250,
"height": 200,
"gravity": "face"
}
}
}'
									
										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,
											* resize the image to 250 x 200, set resize mode to "fit",
											* and gravity set to "face"
											*/

											res, err := pics.Fetch("your-image-url").
												Resize("fit", picsmize.Options{
													"width":  250,
													"height": 200,
													"gravity": "face",
												}).
												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 × 350px
Resizing Of Image
Resize it with "fit" mode setting "width" to 250px, "height" to 200px and crop gravity to "face"
Resizing An Image Online
The resulting image is 250px × 200px focused on a single face

With the gravity set to faces (plural), a similar API call will center the image to show all of the faces:

<?php

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

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

/**
* Provide a publicly available image URL with fetch(string) method,
* resize the image to 250 x 200, set resize mode to "fit",
* and gravity set to "faces"
*/

$picsmize
->fetch('https://www.example.com/image.jpg')
->resize(Picsmize::RESIZE_FIT, array(
'width' => 250,
'height' => 200,
'gravity' => "faces"
))
->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": {
"resize": {
"mode": "fit",
"width": 250,
"height": 200,
"gravity": "faces"
}
}
}'
									
										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,
											* resize the image to 250 x 200, set resize mode to "fit",
											* and gravity set to "faces"
											*/

											res, err := pics.Fetch("your-image-url").
												Resize("fit", picsmize.Options{
													"width":  250,
													"height": 200,
													"gravity": "faces",
												}).
												ToJSON()

											if err != nil {
												panic(err)
											}

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

											fmt.Println(res)
										}
									
								
Resizing Pictures
The resulting image is 250px × 200px focused on all faces detected in the image
Fill

This mode, like auto strategy, demands both width and height characteristics and proportionally resizes the image such that it does not exceed the provided dimensions. The remaining space is subsequently filled with a background that can be either a hex-encoded color, auto, or blurred (see examples below).

To put it another way, I want the image to be at its full width and height, with an empty area filled with a solid background color or a Gaussian-blurred version of the original image

The first background value that can be used is self-explanatory. A hex-encoded string in RRGGBB format can be provided. The default background color is #ffffff. Take a look at an example JSON request and the image that results.

<?php

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

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

/**
* Provide a publicly available image URL with fetch(string) method,
* resize the image to 400 x 300, set resize mode to "fill",
* and background color to "#f0d5c0"
*/

$picsmize
->fetch('https://www.example.com/image.jpg')
->resize(Picsmize::RESIZE_FILL, array(
'width' => 400,
'height' => 300,
'background' => "#f0d5c0"
))
->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": {
"resize": {
"mode": "fill",
"width": 400,
"height": 300,
"background": "#f0d5c0"
}
}
}'
									
										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,
											* resize the image to 400 x 300, set resize mode to "fill",
											* and background color to "#f0d5c0"
											*/

											res, err := pics.Fetch("your-image-url").
												Resize("fill", picsmize.Options{
													"width":  400,
													"height": 300,
													"background": "#f0d5c0",
												}).
												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
Resize it with "fill" mode setting "width" to 400px, "height" to 300px and background color to "#f0d5c0"
Compress Jpeg
The resulting image is 400px × 300px filled with a solid background color

You can also opt to utilize the most dominating color from the input image as the background color. To do so, simply set the background value to auto. The Picsmize API will then swiftly compute the input image's color palette and use the most dominant color, ensuring that your input image blends seamlessly with the background.

<?php

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

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

/**
* Provide a publicly available image URL with fetch(string) method,
* resize the image to 400 x 300, set resize mode to "fill",
* and background color to "auto"
*/

$picsmize
->fetch('https://www.example.com/image.jpg')
->resize(Picsmize::RESIZE_FILL, array(
'width' => 400,
'height' => 300,
'background' => "auto"
))
->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": {
"resize": {
"mode": "fill",
"width": 400,
"height": 300,
"background": "auto"
}
}
}'
									
										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,
											* resize the image to 400 x 300, set resize mode to "fill",
											* and background color to "auto"
											*/

											res, err := pics.Fetch("your-image-url").
												Resize("fill", picsmize.Options{
													"width":  400,
													"height": 300,
													"background": "auto",
												}).
												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 Jpeg
Resize it with "fill" mode setting "width" to 400px, "height" to 300px and background to "auto"
Compressing An Image
The resulting image is 400px × 300px filled with the most dominant color in the input image

Blur is the last potential background value. When the Picsmize API is utilized, it will fill excess space with a Gaussian-blurred version of the input image, providing you the most visually pleasing composition.

<?php

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

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

/**
* Provide a publicly available image URL with fetch(string) method,
* resize the image to 400 x 300, set resize mode to "fill",
* and background set to "blur"
*/

$picsmize
->fetch('https://www.example.com/image.jpg')
->resize(Picsmize::RESIZE_FILL, array(
'width' => 400,
'height' => 300,
'background' => "blur"
))
->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": {
"resize": {
"mode": "fill",
"width": 400,
"height": 300,
"background": "blur"
}
}
}'
									
										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,
											* resize the image to 400 x 300, set resize mode to "fill",
											* and background color to "blur"
											*/

											res, err := pics.Fetch("your-image-url").
												Resize("fill", picsmize.Options{
													"width":  400,
													"height": 300,
													"background": "blur",
												}).
												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
Resize it with "fill" mode setting "width" to 400px, "height" to 300px and background to "blur"
Images Size Reducer
The resulting image is 400px × 300px filled with a blurred version of the original image
Exact

This mode requires both the width and height properties and resizes an image to the precise dimensions supplied. It doesn't take the aspect ratio into account, so you'll have to do the calculations yourself to guarantee that the final image has exact proportions.

To put it another way, I want the image to be the precise width and height.

<?php

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

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

/**
* Provide a publicly available image URL with fetch(string) method,
* resize the image to 300 x 50, set resize mode to "exact",
*/

$picsmize
->fetch('https://www.example.com/image.jpg')
->resize(Picsmize::RESIZE_EXACT, array(
'width' => 300,
'height' => 50
))
->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": {
"resize": {
"mode": "exact",
"width": 300,
"height": 50
}
}
}'
									
										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,
											* resize the image to 300 x 50, set resize mode to "exact",
											*/

											res, err := pics.Fetch("your-image-url").
												Resize("exact", picsmize.Options{
													"width":  300,
													"height": 50,
												}).
												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
Resizing Of Image
Resize it with "exact" mode setting "width" to 300px and "height" to 50px
Resizing An Image Online
The resulting image is exactly 300px × 50px