以下是一个简单的PHP实例,展示了如何使用PHP扩展来处理照片。我们将使用GD库来展示如何读取、修改和输出一张图片

步骤PHP代码
1.读取图片`imagecreatefromjpeg('path/to/image.jpg');`
2.获取图片宽度`$width=imagesx($image);`
3.获取图片高度`$height=imagesy($image);`
4.创建新图片(调整大小)`$newImage=imagecreatetruecolor($newWidth,$newHeight);`
5.复制图片到新图片`imagecopyresampled($newImage,$image,0,0,0,0,$newWidth,$newHeight,$width,$height);`
6.输出新图片`imagejpeg($newImage);`
7.释放内存`imagedestroy($image);`
8.释放新图片内存`imagedestroy($newImage);`

```php

实例:使用PHP扩展处理照片 装修材料

// 设置图片路径

$imagePath = 'path/to/image.jpg';

// 读取图片

$image = imagecreatefromjpeg($imagePath);

// 获取图片宽度和高度

$width = imagesx($image);

$height = imagesy($image);

// 定义新图片的宽度和高度

$newWidth = 500;

$newHeight = 300;

// 创建新图片

$newImage = imagecreatetruecolor($newWidth, $newHeight);

// 复制图片到新图片

imagecopyresampled($newImage, $image, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);

// 输出新图片

imagejpeg($newImage);

// 释放内存

imagedestroy($image);

imagedestroy($newImage);

>

```

这个例子中,我们读取了一张名为`image.jpg`的图片,然后将其调整大小为500x300像素,并输出到浏览器。你可以根据需要修改图片路径和尺寸。