<?php // Plug-in 12: Image Resize // This is an executable example with additional code supplied // To obtain just the plug-ins please click on the Download link // You will need a jpeg image file called test.jpg in this folder $image = imagecreatefromjpeg("test.jpg"); $newim = PIPHP_ImageResize($image, 500, 100); imagejpeg($newim, "squashed.jpg"); echo "This image has been resized to 500 x 100 pixels"; echo "<br /><br /><img src='squashed.jpg'>"; function PIPHP_ImageResize($image, $w, $h) { // Plug-in 12: Image Resize // // This plug-in takes a GD image and resizes it to the // required dimensions. The arguments required are: // // $image: The image source // $w: New width // $h: New height $oldw = imagesx($image); $oldh = imagesy($image); $temp = imagecreatetruecolor($w, $h); imagecopyresampled($temp, $image, 0, 0, 0, 0, $w, $h, $oldw, $oldh); return $temp; } ?>
插件说明:
插件12接受一个需要调整大小的图像和新的宽度和高度。具体如下:
$image 需要调整大小的图像,他作为GD库里的一个对象。
$w 新图像的宽度。
$h 新图像的高度。