perl code to find dimension (width and height) of multiple images that located in image folder and set that dimension in image tag in html pages according their image name.
i am try using this code ,if any one having solution then help me.
#!/usr/bin/perl
use strict;
#use waings;
use Image::Size;
use Cwd;
my $path1 = $ARGV[0];
#print $path1."tAn";
#my $path1 = getcwd;
#$path1="$path1/images/";
opendir(INP, "$path1/") or die "cant open dir";
my @out = grep(/(.*?).(jpg|jpeg|JPG|JEPG|PNG|png|gif|GIF)/,readdir(INP));
#print $2."n";
close INP;
#print $path1;
my $path2 = getcwd;
#print $path2."n";
opendir DIR, $path2 or die "cant open dir";
my @files = grep /(.*?).(html|xhtml)/,(readdir DIR);
closedir DIR;
#print @files."n";
############################ Declaration of Varible #############################
my $total=@out;
my $globe_x;
my $globe_y;
my $format;
#print $globe_x."n";
foreach my $f (@files){
#my $file = $ARGV[0];
open(F1, "<$f");
my $data = join("", <F1>);
close F1;
#print $f."n";
#my $filename = $f;
# my $filename = substr($f, 0, index($f, '.'));
# my $xhtml_file = $filename.".html";
# my $xhtml_file1 = $filename.".xhtml";
my $xml_list = $data;
# my $xml_list1 = $data;
for(my $i=0;$i<$total;$i++)
{
($globe_x, $globe_y, $format) = imgsize("$path1/$out[$i]");
#$xml_list=~s/(<img( style=".*?")? src="(images|image)/$out[$i]"s)(alt=".*?"s?/>)/$1width="$globe_x" height="$globe_y" $4/g;
$xml_list=~s/(<img( style=".*?"| class=".*?")? src="(images|image|Images)/$out[$i]"s?)(alt=".*?"s?/>)/$1width="$globe_x" height="$globe_y" $4/g;
#<img class="center" src="image/pub.png" alt="Logo"/>
}
open(F2, ">$f");
print F2 $xml_list;
close F2;
#print "after $filenamenn";
}
print "Work Completed";
Recent Questions...
ما را در سایت Recent Questions دنبال میکنید
برچسب:
نویسنده: استخدام کار
بازدید: 196
تاريخ: دوشنبه
3 خرداد
1395 ساعت: 21:41