Child pages
  • UAPI Functions - ImageManager::resize_image
Skip to end of metadata
Go to start of metadata

Description

This function resizes a specified image.

Important:

In cPanel & WHM version 76 and later, when you disable the WebServer role, the system disables this function. For more information, read our How to Use Server Profiles documentation.

Examples


 cPanel or Webmail Session URL
https://hostname.example.com:2083/cpsess##########/execute/ImageManager/resize_image?image_file=images/myimage.jpg&width=200&height=300&save_original_as=images/original.jpg


Note:

This example calls the UAPI function via a cPanel session. For more information, read our Guide to UAPI documentation. 

 LiveAPI PHP Class
$cpanel = new CPANEL(); // Connect to cPanel - only do this once.
 
// Resize myimage.jpg.
$resize_image = $cpanel->uapi(
    'ImageManager', 'resize_image',
    array(
        'image_file'     	=> 'images/image.jpg',
		'width'    			=> '200',
		'height'   			=> '300',
		'save_original_as'  => 'images/original.jpg'	
    )
);


Note:

For more information, read our Guide to the LiveAPI System.

 LiveAPI Perl Module
my $cpliveapi = Cpanel::LiveAPI->new(); # Connect to cPanel - only do this once.
 
# Resize myimage.jpg.
my $resize_image = $cpliveapi->uapi(
    'ImageManager', 'resize_image',
    {
        'image_file'     	=> 'images/image.jpg',
		'width'    			=> '200',
		'height'   			=> '300',
		'save_original_as'  => 'images/original.jpg'
    }
);


Note:

For more information, read our Guide to the LiveAPI System.

 cPanel Template Toolkit
<!-- Resize myimage.jpg. -->
    [%
    SET result = execute('ImageManager', 'resize_image',
    {
        'image_file' => 'images/myimage.gif',
        'width' => 200,
        'height' => 250,
        'save_original_as'  => 'images/myimage_original.gif'
    });
    %]
    <p>Resized: [% result.data %] </p>


Note:

For more information, read our Guide to Template Toolkit documentation. 

 Command Line
uapi --user=cptest1 ImageManager resize_image image_file=images/image.jpg width=200 height=300 save_original_as=images/original.jpg


Notes:

  • You must URI-encode values.
  • username represents your account-level username.
  • For more information and additional output options, read our Guide to UAPI documentation or run the uapi --help command. 
  • If you run CloudLinux™, you must use the full path of the uapi command:

    /usr/local/cpanel/bin/uapi


 Output (JSON)
    {
       "apiversion" : 3,
       "result" : {
          "messages" : null,
          "errors" : null,
          "metadata" : {},
          "data" : "/home/cptest1/images/image.jpg",
          "warnings" : null,
          "status" : 1
       },
       "func" : "resize_image",
       "module" : "ImageManager"
    }


Note:

Use cPanel's API Shell interface (cPanel >> Home >> Advanced >> API Shell) to directly test cPanel API calls.

Parameters

ParameterTypeDescriptionPossible ValuesExample
image_filestring

Required

The name of the file to scale.

  • An absolute filepath.
  • A filepath, relative to the user's home directory.
/images/image.jpg
widthinteger

Required

The width to which to set the image size.

The width of the file, in pixels.200
heightinteger

Required

The height to which to set the image size.

The height of the file, in pixels.300
save_original_asstring

The path to the directory in which to save a copy the original image file.

If you don't pass this parameter, the function doesn't save a copy of the original image.

  • An absolute filepath.
  • A filepath, relative to the user's home directory.
images/original.jpg

Returns

ReturnTypeDescriptionPossible valuesExample
data stringThe filepath to the resized image.An absolute filepath./home/cptest1/images/myimage.jpg