php以递归模式对一个目录中的所有图像运行函数
我有一个函数,
$result = create_watermark( 'input_file_name' ,'output_file_name');
我有一个名为 /images
的目录,其中包含 500 张图像。这些文件均名为 images_(some_unknown_numbers).png
(均为 png)。现在我想通过循环中的函数运行它们,并希望输出 /markedimage/images_1.png
、images_2.png
、images_3.png
等等。
我想在 Ubuntu 上运行这个脚本,这样我们也可以使用 shell
我该怎么做?
I have a function
$result = create_watermark( 'input_file_name' ,'output_file_name');
I have directory called /images
with 500 images in it. The files are all named images_(some_unknown_numbers).png
(all png). Now I want run them through a function in a loop and want to output /markedimage/images_1.png
, images_2.png
, images_3.png
and so on.
I want to run this script on Ubuntu so we can use shell too
How can I do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我不确定您是否要重新索引输出文件的数字。这个例子应该保留它们:
I'm not sure whether you want to re-index the numbers for the output files. This example should preserve them:
我使用了第二个答案
,
这个答案没有任何改变:D谢谢,但我不能投票给它,因为我没有注册
@1,我未能使它工作,但我认为如果在它上面付出一些努力,它应该工作,
谢谢尝试并帮助我分配的家伙,我在过去 5 小时内尝试这样做,但失败了,五分钟内就解决了
:D 谢谢xxx
Steve
i used 2nd answer
working one
this answer worked without any change :D thankx but i can't vote for it because i m not registered
@1 i m failed to make it working but this i think if put some effort on it it shud work
thankx to guyz who tried and helped me allot i was try to do this from last 5 hours but failed her it solved in five minutes
:D thankxxx
Steve
未经测试,但这也应该有效:
如果文件夹中的文件不是 png 文件,您可以使用 GlobIterator 而不是 DirectoryIterator,但这需要 PHP5.3。
请参阅
Untested but this should work, too:
If there is files in the folder that are not png files, you can use the GlobIterator instead of the DirectoryIterator, but that would require PHP5.3.
See