Perl的Imgsize不工作在循环? [英] Perl Imgsize not working in loop?
问题描述
#!我已经测试了使用perl获取图像的大小。 / usr / local / bin / perl
使用Image :: Size;
my $ x;
my $ y;
my $ id;
opendir my $ dh,。或死$ 0:opendir:$!;
($ x,$ y,$ id)= imgsize(test_image.png);
print $ x。,。$ y。\\\
;
这工作得很好,它给了我正确的图像宽度和高度。 等等。 为什么 在文件名前添加路径: I've tested getting the image size using perl with the following simple code while sitting in one directory: This worked fine, it gave me the correct width and height of the image.
Then I incorporated it into my larger code, where I'm looping through folders and files.
So the bigger code is this: Now when I run this, I know there's no issue with my paths etc because my output correctly lists the image files in the folders, but it just doesn't output their dimensions: and so on. Why is the Add the path in front of the filename:
这篇关于Perl的Imgsize不工作在循环?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
然后我将它合并到我的更大的代码中,在那里我循环通过文件夹和文件。
所以更大的代码是这样的:
$ $ p $ #我首先进入一个特定的文件夹,文件夹
#每个命名@views阵列中的一个元素
#我已经在其他地方声明
foreach $ view(@views)
{我的$文件夹= $视图;
opendir my $ dh,$ classfolder\\organizedbyviews\\ $ folder\\cropped或死$ 0:opendir:$!;
打印...... \\\
读取文件夹:$ view \\\
..... \\\
;
my $ file;
while($ file = readdir($ dh)){
#读取图片的宽度和高度
my $ w;
my $ h;
my $ id;
($ w,$ h,$ id)= imgsize($ file);
print $ file。:。$ w。,。$ h。\\\
;
$ b现在当我运行这个时,我知道没有问题与我的路径等,因为我的输出正确列出的文件夹中的图像文件,但它只是不输出他们的维度:
$ $ p $ ......
阅读文件夹:view1
......
。:,
..:,
file1.jpg:,
file2.jpg:,
file3.jpg:,
file4.jpg:,
file5.jpg:,
......
读取资料夹:view2
......
。:,
..:,
file1.jpg:,
file2.jpg:,
file3 .jpg:,
file4.jpg:,
file5.jpg:,
imgsize()
函数突然不起作用?
$ file =$ classfolder \\organizedbyviews\\ $ folder\\cropped\\。$ file;
#!/usr/local/bin/perl
use Image::Size;
my $x;
my $y;
my $id;
opendir my $dh, "." or die "$0: opendir: $!";
($x, $y, $id) = imgsize("test_image.png");
print $x." , ".$y."\n";
# I first get into a certain folder, which consists of lots of other folders,
# each named one of the elements in the @views array
# which I've declared somewhere else
foreach $view(@views)
{ my $folder = $view;
opendir my $dh, "$classfolder\\organizedbyviews\\$folder\\cropped" or die "$0: opendir: $!";
print "......\nReading folder: $view \n.....\n";
my $file;
while ($file = readdir($dh)) {
#read the image's width and height
my $w;
my $h;
my $id;
($w, $h, $id) = imgsize($file);
print $file.": ".$w.", ".$h."\n";
}
}
......
Reading folder: view1
......
.: ,
..: ,
file1.jpg: ,
file2.jpg: ,
file3.jpg: ,
file4.jpg: ,
file5.jpg: ,
......
Reading folder: view2
......
.: ,
..: ,
file1.jpg: ,
file2.jpg: ,
file3.jpg: ,
file4.jpg: ,
file5.jpg: ,
imgsize()
function suddenly not working?$file = "$classfolder\\organizedbyviews\\$folder\\cropped\\".$file;