From d2d13b77934735f1c5b1ab33b67c58cf9475d085 Mon Sep 17 00:00:00 2001 From: yossarian Date: Sun, 13 Aug 2006 19:46:46 +0000 Subject: [PATCH] Made the following variables (which deal with the new image resizing code) local rather than instance: private String imagesOriginalDir; private String imagesOriginalDirRelPath; private String imageOriginalFilePath; private String imageOriginalRelPath; Also took out the reference to StreamCopier.copyFile as there was already something in Mir that was designed for this purpose: FileRoutines.copyFile Cleaned up source formatting somewhat to use 2 spaces instead of tabs. Using Integer.toString(foo) rather than new Integer(foo).toString() on Zapata's advice. --- .../mircoders/media/MediaHandlerImagesExtern.java | 97 ++++++++++++---------- 1 file changed, 54 insertions(+), 43 deletions(-) diff --git a/source/mircoders/media/MediaHandlerImagesExtern.java b/source/mircoders/media/MediaHandlerImagesExtern.java index b498aa42..c4fff5a3 100755 --- a/source/mircoders/media/MediaHandlerImagesExtern.java +++ b/source/mircoders/media/MediaHandlerImagesExtern.java @@ -45,6 +45,7 @@ import mir.media.MediaFailure; import mir.media.image.ImageProcessor; import mir.media.image.ImageMagickImageProcessor; import mir.misc.StringUtil; +import mir.util.FileRoutines; /** * Image handler that stores images outside of the database. @@ -60,10 +61,6 @@ public class MediaHandlerImagesExtern extends MediaHandlerGeneric private float minDescaleRatio; private int minDescaleReduction; private boolean scaleImages; - private String imagesOriginalDir; - private String imagesOriginalDirRelPath; - private String imageOriginalFilePath; - private String imageOriginalRelPath; public MediaHandlerImagesExtern() { logger = new LoggerWrapper("Media.Images.Extern"); @@ -72,11 +69,13 @@ public class MediaHandlerImagesExtern extends MediaHandlerGeneric minDescaleRatio = configuration.getFloat("Producer.Image.MinDescalePercentage")/100; minDescaleReduction = configuration.getInt("Producer.Image.MinDescaleReduction"); scaleImages = configuration.getBoolean("Producer.Image.ScaleImages"); - imagesOriginalDir = configuration.getString("Producer.ImagesOriginalDir.Path"); - imagesOriginalDirRelPath = configuration.getString("Producer.ImagesOriginalDir.RelPath"); } public void produce(Entity anImageEntity, Entity mediaTypeEnt) throws MediaExc, MediaFailure { + String imagesOriginalDir = configuration.getString("Producer.ImagesOriginalDir.Path"); ; + String imagesOriginalDirRelPath = configuration.getString("Producer.ImagesOriginalDir.RelPath");; + String imageOriginalFilePath; + String imageOriginalRelPath; try { String date = anImageEntity.getFieldValue("date"); String datePath = StringUtil.webdbDate2path(date); @@ -103,50 +102,62 @@ public class MediaHandlerImagesExtern extends MediaHandlerGeneric if (!imageFile.exists()) { - throw new MediaExc("error in MediaHandlerImagesExtern.execute(): " + filePath + " does not exist!"); - } - else { + throw new MediaExc("error in MediaHandlerImagesExtern.execute(): " + + filePath + " does not exist!"); + } else { ImageProcessor processor = new ImageMagickImageProcessor(imageFile); - - processor.descaleImage(maxIconSize, minDescaleRatio, minDescaleReduction); + processor.descaleImage(maxIconSize, minDescaleRatio, + minDescaleReduction); File dir = new File(iconFile.getParent()); - if (dir!=null && !dir.exists()){ - dir.mkdirs(); + if (dir != null && !dir.exists()) { + dir.mkdirs(); } processor.writeScaledData(iconFile, "JPEG"); - - // yoss: if the config is set so that images should be scaled, make the resized file. - if (scaleImages){ - logger.info("entered scaleImages"); - ImageProcessor originalProcessor = new ImageMagickImageProcessor(imageFile); - originalProcessor.descaleImage(maxSize, minDescaleRatio, minDescaleReduction); - File originalDir = new File(originalFile.getParent()); - if(originalDir!=null && !originalDir.exists()) { - originalDir.mkdirs(); - } - if(!originalFile.exists()) { - logger.debug("the original image file doesn't exist, copying to originalFile"); - StreamCopier.copyFile(imageFile, originalFile); - } - // yoss: don't write the scaled data again if it's the same size as - // the file that's there right now. Image producer runs are 4 times faster this way. - logger.info("about to write scaled data, byte length: " + originalProcessor.getScaledFileSize()); - if (originalProcessor.getScaledFileSize() != imageFile.length()) { - originalProcessor.writeScaledData(imageFile, "JPEG"); - } - anImageEntity.setFieldValue("original_file_path", imageOriginalRelPath); - anImageEntity.setFieldValue("img_height", new Integer(originalProcessor.getScaledHeight()).toString()); - anImageEntity.setFieldValue("img_width", new Integer(originalProcessor.getScaledWidth()).toString()); - - originalProcessor.cleanup(); - + + // yoss: if the config is set so that images should be scaled, make the + // resized file. + if (scaleImages) { + logger.info("entered scaleImages"); + ImageProcessor originalProcessor = new ImageMagickImageProcessor( + imageFile); + originalProcessor.descaleImage(maxSize, minDescaleRatio, + minDescaleReduction); + File originalDir = new File(originalFile.getParent()); + if (originalDir != null && !originalDir.exists()) { + originalDir.mkdirs(); + } + if (!originalFile.exists()) { + logger.debug("the original image file doesn't exist, copying to originalFile"); + FileRoutines.copy(imageFile, originalFile); + } + // yoss: don't write the scaled data again if it's the same size as + // the file that's there right now. Image producer runs are 4 times + // faster this way. + logger.info("about to write scaled data, byte length: " + + originalProcessor.getScaledFileSize()); + if (originalProcessor.getScaledFileSize() != imageFile.length()) { + originalProcessor.writeScaledData(imageFile, "JPEG"); + } + anImageEntity.setFieldValue("original_file_path", + imageOriginalRelPath); + anImageEntity.setFieldValue("img_height", Integer + .toString(originalProcessor.getScaledHeight())); + anImageEntity.setFieldValue("img_width", Integer + .toString(originalProcessor.getScaledWidth())); + + originalProcessor.cleanup(); + } else { - anImageEntity.setFieldValue("img_height", new Integer(processor.getHeight()).toString()); - anImageEntity.setFieldValue("img_width", new Integer(processor.getWidth()).toString()); + anImageEntity.setFieldValue("img_height", new Integer(processor + .getHeight()).toString()); + anImageEntity.setFieldValue("img_width", new Integer(processor + .getWidth()).toString()); } - anImageEntity.setFieldValue("icon_height", new Integer(processor.getScaledHeight()).toString()); - anImageEntity.setFieldValue("icon_width", new Integer(processor.getScaledWidth()).toString()); + anImageEntity.setFieldValue("icon_height", new Integer(processor + .getScaledHeight()).toString()); + anImageEntity.setFieldValue("icon_width", new Integer(processor + .getScaledWidth()).toString()); processor.cleanup(); -- 2.11.0