$image = new Imagick('image.jpg'); // Create image object $width = $image->getWidth(); // Get image width echo "Width: " . $width . " pixels"; // Output width
function getImageWidth($imagePath) { $image = new Imagick($imagePath); // Create image object return $image->getWidth(); // Return width } $width = getImageWidth('image.jpg'); // Get image width echo "Width: " . $width . " pixels"; // Output widthThis example defines a function `getImageWidth` that takes an image file path as a parameter and returns the width of the image in pixels. It uses the `getWidth()` method of the `Imagick` class to retrieve the width. The function is then called with the image file "image.jpg" and the width is outputted. Package Library: `ImageMagick`