visitor (0 QPoints)
  • FR
  • EN
  • NL
  • DE
  • ES
262 experts, 1140 registered users, 1615 questions already answered
European Experts Exchange, the very best site for high-quality IT solutions

We now celebrate our 5 years of existence and break our frequentation records... Here are the stats of those 5 years.

Algorithms :: Imaging :: getting the dimensions of a tif image


By: roe1and Great Britain  Date: 08/04/2008 10:31:13  English  Points: 20 Status: Answered
Quality : Excellent
i have been looking into compiling a list of all the images on our server here at work and their dimensions(maybe dpi too, if possible). i don't know anything about image headers. i just need some idea of how to approach this. would i be able to do this using unix? could php do this(of course this wouldn't help because i can't use php at work, although lately i've been doing things in php and then converting them to perl). if anyone could just suggest a starting point i would appreciate it!
By: VGR Date: 08/04/2008 19:46:50 English  Type : Answer
of course PHP can get info about TIFFs ;-)

It's a format covered by GD : http://www.php.net/manual/en/ref.image.php

You may use PHP in CLI (console, like DOS) mode by simply copying the php.exe and php5ts.dll files...

moreover, PHP can handle natively Perl scripts, so you could use it anyway. Just mount your own local webserver ;-)
By: roe1and Date: 09/04/2008 11:36:38 English  Type : Comment
i've been working for this company for months and only today i found out i can run php scripts that can directly access the information on the servers! i've been struggling my ass off with perl and what not nonsense. this is great!

ok. one more question. at the moment i have this:
<?php
$dir = "/sd/web/images/pao/0007/1899/0000";

if (is_dir($dir)) {

if ($dh = opendir($dir)) {

while (($file = readdir($dh)) !== false) {

if ($file != "." && $file != "..") {
echo $file. '
';

$img = $dir.'/'.$file;
echo $img. '
';
list($width, $height, $type, $attr) = getimagesize($img);
echo $attr.'
';

}
}
closedir($dh);
}
}
?>

i think this is pretty straight forward. but how can i make the script read the subdirectories too. the directories for the images looks something like this:

/sd/web/images/pao/0007/1899/0000
/sd/web/images/pao/0007/1899/0001
/sd/web/images/pao/0007/1899/0002
/sd/web/images/pao/0007/1900/0000
/sd/web/images/pao/0007/1900/0001
/sd/web/images/pao/0007/1900/0002
etc.

so what i would like to do is just have:
$dir = "/sd/web/images/pao/0007";
and then let the script do the rest?
By: roe1and Date: 09/04/2008 13:25:10 English  Type : Comment
my final solution: not pretty, but it works

$dir = "/sd/web/images/pao/0007";

if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
if ($file != "." && $file != "..") {

$sdir = $dir.'/'.$file;
if (is_dir($sdir)) {
if ($dh1 = opendir($sdir)) {
while (($file1 = readdir($dh1)) !== false) {
if ($file1 != "." && $file1 != "..") {

$ssdir = $sdir.'/'.$file1;
if (is_dir($ssdir)) {
if ($dh2 = opendir($ssdir)) {
while (($file2 = readdir($dh2)) !== false) {
if ($file2 != "." && $file2 != "..") {

$thedamnfile = $ssdir.'/'.$file2;
echo $thedamnfile. ': ';
list($width, $height, $type, $attr) = getimagesize($thedamnfile);
echo $attr.'
';

}
}
closedir($dh2);
}
}

}
}
closedir($dh1);
}
}

}
}
closedir($dh);
}
}
echo 'done';
}
By: VGR Date: 09/04/2008 20:44:29 English  Type : Comment
the natural solution to this is a recursive function, but it's probably better to limit the depth you'd go (say, 5 levels?). you may also copy-paste-and-indent 5 levels of loops for subdirectories. Why not. Ugly, but efficient.
By: VGR Date: 17/04/2008 13:57:47 English  Type : Comment
I was wrong above, GD doesn't really support TIFF. Imagick does. Sorry.
By: roe1and Date: 17/04/2008 20:54:30 English  Type : Comment
it works for me. my script spits out the dimensions nicely

Do register to be able to answer

 Add This Article To:
 del.icio.usDel.icio.us  diggDigg  googleGoogle  spurlSpurl
 blinkBlink  wongWong  simpySimpy  yahooY! MyWeb 
EContact
browser fav
page generated in 4541.893960 milliseconds

Why Google AdSense ads ?

compteur
 Ranking-Hits PageRank for this page