$im = new Imagick(); $file = fopen("image.jpg", "rb"); $blob = fread($file, filesize("image.jpg")); fclose($file); $im->readImageBlob($blob); $im->thumbnailImage(100, 100); header("Content-Type: image/jpg"); echo $im;
$im = new Imagick(); $conn = new PDO("mysql:host=localhost;dbname=mydatabase", "username", "password"); $stmt = $conn->prepare("SELECT image_blob FROM images WHERE id = ?"); $stmt->execute(array($_GET['id'])); $row = $stmt->fetch(PDO::FETCH_ASSOC); $blob = $row['image_blob']; $im->readImageBlob($blob); header("Content-Type: image/png"); echo $im;In this example, we use PDO to access a database and retrieve an image stored as a binary blob. We then pass the blob to readImageBlob() to read it as an image and output it to the browser.