// Load the image into Imagick $image = new Imagick('path/to/image.jpg'); // Resize the image to fit within a 200x200 pixel area, while preserving aspect ratio $image->adaptiveResizeImage(200, 200); // Save the resized image $image->writeImage('path/to/resized-image.jpg');
// Load the image into Imagick $image = new Imagick('path/to/image.jpg'); // Get the current size of the image $size = $image->getImageGeometry(); // Calculate the aspect ratio $aspectRatio = $size['width'] / $size['height']; // Resize the image to fit within a 400x400 pixel area, while preserving aspect ratio $image->adaptiveResizeImage(400, round(400 / $aspectRatio)); // Save the resized image $image->writeImage('path/to/resized-image.jpg');This example is similar to the first example, except that it calculates the aspect ratio based on the size of the original image. This allows you to resize the image to fit within a specific area while still preserving aspect ratio. The adaptiveResizeImage function is part of the Imagick PHP extension, which is a wrapper around the ImageMagick C library. This library provides a powerful set of image manipulation functions that can be used to create and modify images in a wide variety of ways.