def _process(self):
     '''
     Run the different methods to preprocess the images in source folder
     '''
           
     #=======================================================================
     # # Initialize dictionary for image processing information
     #=======================================================================
     self.getImageInformation()
     #=======================================================================
     # If 'spread_detection' is True, get size of all images and set
     # them as spreads if they are statistically large (larger than mean or
     # avg adjusted with some constant)
     # A spread is exclude from cropping and deskewing 
     #=======================================================================
     if self.settings['spread_detection']: self.locate_spreads()
     if self.settings['crop_images']:
         #=======================================================================
         # Get all cropping coordinates and evaluate these
         #=======================================================================
         self.getCropCoordinates()
         #=======================================================================
         # Select crop coordinates
         #=======================================================================
         self.set_crop()
         #=======================================================================
         # Crop images e.g. with output to bw-image file in temp folder ->  
         # smaller and bw may be better for deskew test?
         #=======================================================================
         if self.settings['deskew_images']: self.create_temp_crops()
     if self.settings['deskew_images']:
         #=======================================================================
         # Get all deskew
         #=======================================================================
         self.get_deskew_angles()
         #===================================================================
         # Select which images to deskew 
         #===================================================================
         self.set_deskew()
         #===================================================================
         # Process files
         #===================================================================
     self.processFiles()
     if self.debug: self.logger.debug(pprint.pformat(self.img_proc_info))
     if self.debug: self.logger.debug(str(datetime.datetime.now())+': '+'Merge pdf files to one pdf')
     #=======================================================================
     # If output to pdf is set to True, merge output pdfs for each page to
     # one pdf
     # NB: only used for testing purposes
     #=======================================================================
     if self.settings['output_pdf']:
         pdf_tools.mergePdfFilesInFolder(self.temp_pdf_folder,self.pdf_dest)
def createPdfFromFolder(src, file_dest,temp_folder,
                        quality=50,resize_pct=50,valid_exts=['jpg','tif']):
    '''
    Use ImageMagick to create one pdf from all the images in a folder and 
    output to a given destination.
    
    Create a pdf of each image and place in temp folder. Merge output pdf-files
    to pdf-dest and remove temp folder.
    
    '''
    image_paths = fs.getFilesInFolderWithExts(src, valid_exts)
    for image in image_paths:
        # Handle spaces in filenames
        image = '"' + image + '"'
        input_path = os.path.join(src,image)
        file_name,_ = os.path.splitext(image)
        output_file_name = file_name+'.pdf'
        output_path = os.path.join(temp_folder,output_file_name)
        image_tools.compressFile(input_path, output_path, quality, resize_pct)
    pdf_misc.mergePdfFilesInFolder(temp_folder,file_dest)
    fs.clear_folder(temp_folder,also_folder=True)