新手需要有关获取数据并以可用格式返回数据的脚本的建议
我有大量图像要放入网页中。我认为我可以编写一个脚本来完成这项工作,而不是费力地输入所有图像属性。我只需要朝着正确的方向一点点推动。
我希望脚本获取每个图像的宽度和高度,然后将其格式化为包含我正在使用的 url 的 img 标签。我想首先我会循环遍历目录中的文件并将我正在查找的结果输出到文件中。然后我就可以复制和粘贴了。
理想情况下,它最终应该有一个 GUI,您可以在其中选择每个文件,将结果保存到剪贴板,然后将其直接粘贴到文档中。但我相信目前这超出了我的能力范围。
我对编码有基本的了解,并且用 Python 和 PHP 编写了一些脚本。
我从哪里开始?我可以使用Python吗?还是PHP?或者不同的语言? PHP 有 getimagesize() 函数,可以返回我需要的数据。 Python有类似的功能吗?
抱歉啰嗦了。感谢您的任何意见。
I have a large number of images that I am putting into web pages. Rather than painstakingly enter all of the image attributes, I thought I could write a script that would do the work for me. I just need a little push in the right direction.
I want the script to get the width and height of each image, then format this into an img tag that would include the url I'm using. I'm thinking that first I would loop through the files in the directory and output the results that I'm looking for to a file. Then I can copy and paste.
Ideally, it should eventually have a GUI where you can choose each file, save the result to the clipboard, then paste it directly into the document. But I believe this is beyond me at this point.
I have a basic understanding of coding and have done a smattering of scripts in Python and PHP.
Where do I start? Can I use Python? Or PHP? Or a different language? PHP has the getimagesize() function that returns the data I need. Does Python have a similar function?
Sorry to be long winded. And thanks for any input.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
查看 PIL:
有关循环文件,请参阅 本教程。
Check out the PIL:
For looping through files see this tutorial.
也许更好的解决方案不是创建一个脚本来生成所有图像元素的列表以供您放入文档中,而是在所需文档中动态生成图像元素。这可以这样做:
此外,我不明白为什么你想要在 img 元素中包含图像高度和宽度,因为不需要指定这些。高度和宽度仅用于修改图像尺寸,因为浏览器会自动显示实际尺寸。
但要包括图像大小, getimagesize() 函数可以工作:
更多信息: http://nl2.php .net/function.getimagesize
Maybe the better solution would be not to create a script that generates a list of all the image elements for you to put in your document but rather generate the image elements on the fly in the desired document. This could be done like this:
Furthermore I don't understand why you would want to include image height and width in the img elements as there is no need to specify those. The height and the width are only used to modify the image dimensions as the browser automatically display's the actual size.
But to include the image size the getimagesize() function would work:
more info: http://nl2.php.net/function.getimagesize
您还可以使用 identify 命令.imagemagick.org/script/index.php" rel="nofollow noreferrer">Imagemagick:
You can also use shell identify command from Imagemagick:
我认为这应该做你想做的。但这不一定是最好的方法(已经晚了,我累了,等等......):
I think this should do what you want. But it's not necessarily the best way (it's late, I'm tired, etc...):