开发者

Imagick and html tags

开发者 https://www.devze.com 2023-04-03 19:02 出处:网络
I\'m trying to make a thumbnail imag开发者_如何学JAVAe on the go with imagick. Everything works fine when i use this code:

I'm trying to make a thumbnail imag开发者_如何学JAVAe on the go with imagick.

Everything works fine when i use this code:

<?php
header('Content-type: image/jpeg');
$source = "image.jpg";
$image = new Imagick();
$image->readImage ($source);
$image->cropThumbnailImage( 160, 120 );
echo $image;
?>

but when I wrap it with <html> and <body> tags I get all those strange characters like:

ÿØÿàJFIFHHÿÛC !"$"$ÿÛC

I couldn't find anywhere hot to use imagick with html tags.

Please help, thanks.


You need to put that php code above into a separate file, for example thumbNail.php Then on your html page, you call up the created image, by referencing that file in the src attribute like this for example:

<img src="thumbNail.php" />

You can't put any html markup inside the PHP file, because the browser is expecting to get an image back, not html (This happens because you set the content-type header to an image)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号