快速调整图片工具/脚本 [英] Fast resize picture tool/script

查看:123
本文介绍了快速调整图片工具/脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在按日期组织的服务器上的文件夹中有很多图像(500,000 +)。我制作了一个PHP脚本来复制和裁剪子文件夹(拇指)上的每个JPG文件,但由于PHP不支持多线程,所以它非常慢。

I have a lot of images (500,000 +) in a folder on the server organized by date. I made a PHP script to copy and crop each JPG file on a subfolder (thumb), but it's very slow since PHP doesn't support multithreading.

我想知道如何继续。 Python是一个很好的选择吗?有没有一个好的工具,或者我如何改进我的调整大小功能?

I want advice on how to proceed. Is Python a good option for this? Is there a good tool, or how can I improve my resize function?

您还可以查看我的 PHP代码

推荐答案

你可以在没有任何PHP的情况下完成它问题,模拟线程而不是直接使用它们。实际上,PHP没有本机线程(你可以使用库来使用库,但这在你的情况下并不是很有用)。

You can do it in PHP without any problem, simulating threads instead of using them directly. Actually, PHP doesn't have native threads (you can eventuall¥ use libraries but that's not very useful in your case).

在您的代码中,而不是调用:

In your code, instead of calling :

static::Crop($file,$destination,$tn_w = 300,$tn_h =200,$quality = 100,$wmsource = false);

为什么不这样做:

$array = array($file, $destination, $tn_w = 300, $tn_h = 200, $quality = 100, $wmsource = 0);
$command = "/usr/bin/php crop.php";
foreach ($array as $arg)
{
  $command .= ' ' . escapeshellarg($arg);
}
exec("$command &"); // note the & which release your execution
usleep(100000);

你把你的裁剪功能放在 crop.php ,然后将其称为:

And you put your cropping function inside crop.php, and then call it like :

list($exec, $file, $destination, $tn_w, $tn_h, $quality, $wmsource) = $argv;
static::Crop($file,$destination,$tn_w = 300,$tn_h =200,$quality = 100,$wmsource = false);

这将完成这项工作。

如果您想避免睡眠并控制一次运行多少作物,您也可以使用文件模拟互斥锁,这完全取决于您。你绝对可以用PHP做这样的工作。

You can also simulate mutexes using a file if you want to avoid usleep and control how many crops are running at once, that's really up to you. You definitely can do such work in PHP.

这篇关于快速调整图片工具/脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆