OSDN Git Service

change jpeg cache folder division.
authorgn64_jp <gn64@rec10.org>
Wed, 31 Jul 2013 13:46:29 +0000 (22:46 +0900)
committergn64_jp <gn64@rec10.org>
Wed, 31 Jul 2013 13:46:29 +0000 (22:46 +0900)
index/pdf2xml.py
www/jpegserver.pl

index 23825e5..d94f411 100644 (file)
@@ -43,6 +43,9 @@ except:
 if (extendJpeg==1):
     if not(os.path.exists(cacheFolder)):
         os.system("mkdir \""+cacheFolder+"\"")
+        os.system("mkdir \""+cacheFolder+"/orig/\"")
+        os.system("mkdir \""+cacheFolder+"/900/\"")
+        os.system("mkdir \""+cacheFolder+"/2000/\"")
         os.system("chmod -R 777 \""+cacheFolder+"\"")
 dbcon=sqlite3.connect(sqlpath,isolation_level=None)
 try:
@@ -162,13 +165,13 @@ def TEXT2solr(solrcon,titletxt,textpath,pagenum,pagemax,pdfpath,idnum):
     #print sdata
     solrcon.add(sdata)
 def generateCache(pdfpath,filename,pagenum):
-    cacheJpegPath=cacheFolder+"/"+filename+"_orig.jpg"
+    cacheJpegPath=cacheFolder+"/orig/"+filename+"_orig.jpg"
     if extendJpeg==1:
         os.system("pdfimages -j -f "+str(pagenum)+" -l "+str(pagenum)+" \""+pdfpath+"\" \""+cacheFolder+"/"+filename+"\"")
         os.system("mv \""+cacheFolder+"/"+filename+"-000.jpg\" \""+cacheJpegPath+"\"")
         os.system("jpegtran -copy none -optimize -outfile \""+cacheJpegPath+"\" \""+cacheJpegPath+"\"")
     if adjustForiOS==1:
-        cacheMobileJpegPath=cacheFolder+"/"+filename+"_mobile.jpg"
+        cacheMobileJpegPath=cacheFolder+"/900/"+filename+"_mobile.jpg"
         os.system("gm convert -quality 60 -size 900x1704 -resize 900x1704\\> \""+cacheJpegPath+"\" \""+cacheMobileJpegPath+"\"")
         os.system("jpegtran -copy none -optimize -outfile \""+cacheMobileJpegPath+"\" \""+cacheMobileJpegPath+"\"")
 argvs=sys.argv
index 01b66ca..1917677 100755 (executable)
@@ -13,6 +13,8 @@ use DBD::SQLite;
 #use Data::Dumper;
 use YAML::XS;
 
+#use KCatch;
+
 # Libre10 - yet another hoge -
 # Copyright (C) 2013 yukikaze,long.inus
 #
@@ -38,10 +40,11 @@ $pagediff   = int( $cgi->param('pagediff') );
 $dpi        = int( $cgi->param('dpi') );
 $width      = int( $cgi->param('width') );
 $height     = int( $cgi->param('height') );
-$raw           = int( $cgi->param('raw'));
+$raw        = int( $cgi->param('raw') );
 $mode       = $cgi->param('mode');
 $outputpath = "/tmp/libre10/tmp" . generate_unique_key();
 $dbpath     = $confdata->{dburl};
+$cachepath  = $confdata->{cacheFolder};
 $dbi =
   DBI->connect( "dbi:SQLite:dbname=$dbpath", "", "",
        { RaiseError => 1, AutoCommit => 1 } );
@@ -51,35 +54,64 @@ $dbi_state->execute();
 $pdfpath = $dbi_state->fetchrow_array;
 $dbi->disconnect;
 
+@extlist = ( ".pdf", ".PDF" );
+( $tfn, $filetitle, $text ) = fileparse( $pdfpath, @extlist );
+
 if ( -e "/tmp/libre10" ) {
 }
 else {
        system "mkdir /tmp/libre10";
 }
-if ( ( -e $pdfpath ) && ( -r $pdfpath ) ) {
-       $b = $pagenum - $pagediff;
-       $e = $pagenum + $pagediff;
-       if ( $b < 1 ) {
-               $b = 1;
+$tmpcachepath    = $outputpath;
+$cachepathmobile = "$cachepath/900/$filetitle" + "_$pagenum" + "_mobile.jpg";
+$cachepath       = "$cachepath/orig/$filetitle" + "_$pagenum" + "_orig.jpg";
+$useCache        = ( -e $cachepath );
+if ($useCache) {
+       $outputpathjpg = $cachepath;
+}
+else {
+       if ( ( -e $pdfpath ) && ( -r $pdfpath ) ) {
+               $b = $pagenum - $pagediff;
+               $e = $pagenum + $pagediff;
+               if ( $b < 1 ) {
+                       $b = 1;
+               }
+               system
+                 "pdfimages -f $pagenum -l $pagenum -j \"$pdfpath\" \"$outputpath\"";
        }
-       system "pdfimages -f $pagenum -l $pagenum -j '$pdfpath' $outputpath";
+       $outputpathjpg = "$outputpath-000.jpg";
 }
-$outputpathjpg = "$outputpath-000.jpg";
 if ( ( $width > 0 ) or ( $height > 0 ) ) {
-       if ( $raw > 0 ){
-               //
-       }else{
+       if ( $raw > 0 ) {
+               //;
+       }
+       else {
                if ( ( $width > 0 ) and !( $height > 0 ) ) {
                        $height = 2 * $width;
                }
                if ( !( $width > 0 ) and ( $height > 0 ) ) {
                        $width = 2 * $height;
                }
-               if ( $width > 0 && $height > 0 ) {
-                       $outputpath_rs_jpg = "$outputpath-000-$width-$height.jpg";
-                       generate_resized_image( $outputpathjpg, $outputpath_rs_jpg, $width,
-                       $height );
-                       $outputpathjpg = $outputpath_rs_jpg;
+               if ( $width < 2100 && $height < 2100 ) {
+                       if ( $width < 1000 && $height < 1000 ) {
+                               if ( $width > 0 && $height > 0 ) {
+                                       $outputpath_rs_jpg = "$tmpcachepath-000-$width-$height.jpg";
+                                       generate_resized_image( $outputpathjpg, $outputpath_rs_jpg,
+                                               $width, $height );
+                                       $outputpathjpg = $outputpath_rs_jpg;
+                               }
+                       }
+                       else {
+                               if ( -e $cachepathmobile ) {
+                                       $outputpathjpg = $cachepathmobile;
+                               }
+                               else {
+                                       $outputpath_rs_jpg = "$tmpcachepath-000-$width-$height.jpg";
+                                       generate_resized_image( $outputpathjpg, $outputpath_rs_jpg,
+                                               $width, $height );
+                                       $outputpathjpg = $outputpath_rs_jpg;
+                               }
+                       }
                }
        }
 }