webCOMAND

ImageData::resize()

Resize image based on a width and height.

Prototype

void static resize($width, $height, $exact = false)

Parameters

  • width - Number of pixels wide to resize the image.  If the exact option is set to true, the resulting image will be exactly the specified width.  Otherwise, it will be specified width or less.  If zero is specified, the width will be ignored and scale proportionally to the specified height.
  • height - Number of pixels high to resize the image.  If the exact option is set to true, the resulting image will be exactly the specified height.  Otherwise, it will be the specified height or less.  If zero is specified, the height will be ignored and scale proportionally to the specified width.
  • exact - If TRUE, set the image to the exact width and height specified, warping the image if needed.  If FALSE, fit the new image width and height within the specified width and height, scaling it proportionally as appropriate.  Default is TRUE.

Example

// Load a PNG image from the web (PNG)
$url = 'https://www.webcomand.com/docs/img/note.png';
$png = get_file_contents($url);
$image = new \io_comand_image\models\ImageData($png);

// Resize the image proportionally to 320 pixels wide
$image->resize(320, 0);

// Change the image format to JPEG
$image->set_format('JPEG');

// Write the PNG image to the file system
file_put_contents('logo.jpg', $image);