使用php复制、调整大小、移动图像


copy, resize, move image with php

我想要复制、调整大小和移动图像。这是wordpress如何在上传时创建不同大小的图像的模拟。我希望这是可执行的,而不上传任何东西,只是在你运行页面时运行。

示例:

$imagePath = 'http://example.com/images/myimageonserver.jpg';
$newImagePath = 'http://example.com/images/new/myimageonserver.jpg';
$newImageWidth = 300;
$newImageHeight = 200;

有人知道能做到这一点的剧本吗?或者一些有用的函数可以实现这一点。

我不久前写了这个类来包装GD库函数。

你可以这样称呼它:

$image = new Image('original/path/to.file', 'destination/of/resized.file');
$image->resize(300, 200);
$image->output();
$image->clean();

更新:

这个类不再像上面解释的那样工作
这里有一个新的例子:

$image = new Image();
$image->source('original/path/to.file');
$image->destination('destination/of/resized.file');
$image->Manipulate->Resize(300,200);
$image->output();
$image->clean();

您尝试过GD库吗?动力很好。

使用GD-Lib或ImageMagick。对于ImageMagick,它是resizeImage函数。

我不确定这是否是你想要实现的,但看看这是否有帮助:

http://php.net/manual/en/function.imagecopyresized.php

您可以使用基于GD库的ImageWorkshop类:http://phpimageworkshop.com/(在github上:https://github.com/Sybio/ImageWorkshop)