- generate proper png and thumb filenames

This commit is contained in:
Richard Alam 2020-02-20 13:42:37 -08:00
parent 2fbd2821f4
commit 3864fef3ea
2 changed files with 23 additions and 16 deletions

View File

@ -68,8 +68,9 @@ public class PngCreatorImp implements PngCreator {
}
long start = System.currentTimeMillis();
renamePng(pngDir, page);
// Create blank thumbnails for pages that failed to generate a thumbnail.
createBlankPngs(pngDir, page);
createBlankPng(pngDir, page);
long end = System.currentTimeMillis();
System.out.println("*** GENERATE BLANK PNG " + (end - start));
@ -110,7 +111,7 @@ public class PngCreatorImp implements PngCreator {
}
String COMMAND = "";
dest = pngsDir.getAbsolutePath() + File.separator + "slide"; // the "-x.png" is appended automagically
dest = pngsDir.getAbsolutePath() + File.separator + TEMP_PNG_NAME; // the "-x.png" is appended automagically
COMMAND = "pdftocairo -png -scale-to " + slideWidth + " -f " + page + " -l " + page + " " + source + " " + dest;
System.out.println("********* CREATING PNGs " + COMMAND);
@ -139,7 +140,7 @@ public class PngCreatorImp implements PngCreator {
return new File(presentationFile.getParent() + File.separatorChar + "pngs");
}
private void renamePng(File dir) {
private void renamePng(File dir, int page) {
/*
* If more than 1 file, filename like 'temp-png-X.png' else filename is
* 'temp-png.png'
@ -159,10 +160,13 @@ public class PngCreatorImp implements PngCreator {
// 3. .png
// We are interested in the second match.
int pageNum = Integer.parseInt(matcher.group(2).trim());
String newFilename = "slide-" + (pageNum) + ".png";
File renamedFile = new File(
dir.getAbsolutePath() + File.separator + newFilename);
files[i].renameTo(renamedFile);
if (pageNum == page) {
String newFilename = "slide-" + (page) + ".png";
File renamedFile = new File(
dir.getAbsolutePath() + File.separator + newFilename);
files[i].renameTo(renamedFile);
}
}
}
} else if (dir.list().length == 1) {
@ -175,7 +179,7 @@ public class PngCreatorImp implements PngCreator {
}
}
private void createBlankPngs(File pngsDir, int page) {
private void createBlankPng(File pngsDir, int page) {
File png = new File(pngsDir.getAbsolutePath() + File.separator + "slide-" + page + ".png");
if (!png.exists()) {
log.info("Copying blank png for slide {}", page);

View File

@ -56,7 +56,6 @@ public class ThumbnailCreatorImp implements ThumbnailCreator {
if (!thumbsDir.exists())
thumbsDir.mkdir();
try {
success = generateThumbnail(thumbsDir, pres, page);
} catch (InterruptedException e) {
@ -64,10 +63,12 @@ public class ThumbnailCreatorImp implements ThumbnailCreator {
success = false;
}
renameThumbnails(thumbsDir, page);
// Create blank thumbnails for pages that failed to generate a thumbnail.
createBlankThumbnail(thumbsDir, page);
//renameThumbnails(thumbsDir);
return success;
}
@ -83,7 +84,7 @@ public class ThumbnailCreatorImp implements ThumbnailCreator {
COMMAND = IMAGEMAGICK_DIR + File.separatorChar + "convert -thumbnail 150x150 "
+ source + " " + dest;
} else {
dest = thumbsDir.getAbsolutePath() + File.separatorChar + "thumb"; // the "-x.png" is appended automagically
dest = thumbsDir.getAbsolutePath() + File.separatorChar + TEMP_THUMB_NAME; // the "-x.png" is appended automagically
COMMAND = "pdftocairo -png -scale-to 150 " + " -f " + page + " -l " + page + " " + source + " " + dest;
}
@ -115,7 +116,7 @@ public class ThumbnailCreatorImp implements ThumbnailCreator {
presentationFile.getParent() + File.separatorChar + "thumbnails");
}
private void renameThumbnails(File dir) {
private void renameThumbnails(File dir, int page) {
/*
* If more than 1 file, filename like 'temp-thumb-X.png' else filename is
* 'temp-thumb.png'
@ -135,10 +136,12 @@ public class ThumbnailCreatorImp implements ThumbnailCreator {
// 3. .png
// We are interested in the second match.
int pageNum = Integer.valueOf(matcher.group(2).trim()).intValue();
String newFilename = "thumb-" + (pageNum) + ".png";
File renamedFile = new File(
dir.getAbsolutePath() + File.separatorChar + newFilename);
file.renameTo(renamedFile);
if (pageNum == page) {
String newFilename = "thumb-" + (page) + ".png";
File renamedFile = new File(
dir.getAbsolutePath() + File.separatorChar + newFilename);
file.renameTo(renamedFile);
}
}
}
} else if (dir.list().length == 1) {