Mega Code Archive

 
Categories / Php / Graphics
 

Extended EPS Information

<?php <html> <head> <title>EPSInfo</title> </head> <body> <table border="0" width="80%" cellspacing="2" cellpadding="0"> <tr bgcolor="#cccccc"> <th>Name</th><th>Width</th><th>Height</th><th>Resolution</th><th>Mode</th></tr> <?php // read EPS data of given filename function read_eps($img){ $fp=fopen ($img, "rb"); $buffer = fread($fp, 4096); // assume information is in first 4096 bytes if (!preg_match("/ImageData:[^\"]*\"/",$buffer ,$imgdataln)) { // if not, try first 10kbyte fclose($fp); $fp=fopen ($img, "rb"); $buffer = fread($fp, 100000); if (!preg_match("/ImageData:[^\"]*\"/",$buffer ,$imgdataln)) { // if still not found, try whole file fclose($fp); $fp=fopen ($img, "rb"); $buffer = fread($fp,filesize($img)); preg_match("/ImageData:[^\"]*\"/",$buffer ,$imgdataln); } } $imgdata=split(" ", $imgdataln[0]); // Read image width and height if (preg_match("/BoundingBox:[^\"]*\"/",$buffer ,$imgdataln2)) { $imgdata2=split(" ", $imgdataln2[0]); // Read Bounding data } if (preg_match("/DocumentProcessColors:[^\"]*\"/",$buffer ,$imgdataln3)) { $imgcolour=split(" ", $imgdataln3[0]); //Read Color format } fclose ($fp); $imgwidth=$imgdata[1]; // get image width $imgheight=$imgdata[2]; // get image height if ($imgdata2[3] > 0) { $imgres=(72/$imgdata2[3])*$imgdata[1];} // calculate image resolution in dpi if ((290 < $imgres) and ($imgres < 310)) {$imgres=300;} // make it look like 300 dpi if ($imgcolour[1]=="Cyan") { $imgcolor = "CMYK"; // make Color look like CMYK } else { $imgcolor = "no CMYK information found"; } if ($imgwidth[1]=='') { $bgcolor='#FFAAAA'; } else { $bgcolor='#AAFFAA'; } print "<tr bgcolor='$bgcolor'><td>".$img."</td>\n"; // print tablerow print "<td align=\"right\">".$imgwidth."&nbsp;px</td>\n"; print "<td align=\"right\">".$imgheight."&nbsp;px</td>\n"; print "<td>".round($imgres)."&nbsp;dpi</td>\n"; print "<td>".$imgcolor."</td>\n"; } chdir($img_path); // first move to image path $fh = opendir("."); // open filehandle while (($filen = readdir($fh)) !== false) // read all files in folder { if (($filen != ".") && ($filen != "..")) { read_eps($filen); } } closedir($fh); ?> </table> </body> </html>