def get_preview_size(self): dimensions = [] dimensions.append(unicode(self.preview_width)) if self.preview_height: dimensions.append(unicode(self.preview_height)) return DIMENSION_SEPARATOR.join(dimensions)
def get_preview_size(self): dimensions = [] dimensions.append(force_text(self.preview_width)) if self.preview_height: dimensions.append(force_text(self.preview_height)) return DIMENSION_SEPARATOR.join(dimensions)
def convert_file(self, input_filepath, output_filepath, transformations=None, page=DEFAULT_PAGE_NUMBER, file_format=DEFAULT_FILE_FORMAT): arguments = [] try: if transformations: for transformation in transformations: if transformation['transformation'] == TRANSFORMATION_RESIZE: dimensions = [] dimensions.append(unicode(transformation['arguments']['width'])) if 'height' in transformation['arguments']: dimensions.append(unicode(transformation['arguments']['height'])) arguments.append(u'-resize') arguments.append(u'%s' % DIMENSION_SEPARATOR.join(dimensions)) elif transformation['transformation'] == TRANSFORMATION_ZOOM: arguments.append(u'-resize') arguments.append(u'%d%%' % transformation['arguments']['percent']) elif transformation['transformation'] == TRANSFORMATION_ROTATE: arguments.append(u'-rotate') arguments.append(u'%s' % transformation['arguments']['degrees']) except: pass if file_format.lower() == u'jpeg' or file_format.lower() == u'jpg': arguments.append(u'-quality') arguments.append(u'85') # Graphicsmagick page number is 0 base input_arg = u'%s[%d]' % (input_filepath, page - 1) # Specify the file format next to the output filename output_filepath = u'%s:%s' % (file_format, output_filepath) command = [] command.append(unicode(GM_PATH)) command.append(u'convert') command.extend(unicode(GM_SETTINGS).split()) command.append(unicode(input_arg)) if arguments: command.extend(arguments) command.append(unicode(output_filepath)) proc = subprocess.Popen(command, close_fds=True, stderr=subprocess.PIPE, stdout=subprocess.PIPE) return_code = proc.wait() if return_code != 0: #Got an error from convert program error_line = proc.stderr.readline() if (CONVERTER_ERROR_STRING_NO_DECODER in error_line) or (CONVERTER_ERROR_STARTS_WITH in error_line): #Try to determine from error message which class of error is it raise UnknownFileFormat else: raise ConvertError(error_line)
def convert_file(self, input_filepath, output_filepath, transformations=None, page=DEFAULT_PAGE_NUMBER, file_format=DEFAULT_FILE_FORMAT, **kwargs): arguments = [] try: if transformations: for transformation in transformations: if transformation[ 'transformation'] == TRANSFORMATION_RESIZE: dimensions = [] dimensions.append( unicode(transformation['arguments']['width'])) if 'height' in transformation['arguments']: dimensions.append( unicode(transformation['arguments']['height'])) arguments.append(u'-resize') arguments.append(u'%s' % DIMENSION_SEPARATOR.join(dimensions)) elif transformation[ 'transformation'] == TRANSFORMATION_ZOOM: arguments.append(u'-resize') arguments.append( u'%d%%' % transformation['arguments']['percent']) elif transformation[ 'transformation'] == TRANSFORMATION_ROTATE: arguments.append(u'-rotate') arguments.append( u'%s' % transformation['arguments']['degrees']) except: pass if file_format.lower() == u'jpeg' or file_format.lower() == u'jpg': arguments.append(u'-quality') arguments.append(u'85') # Graphicsmagick page number is 0 base input_arg = u'%s[%d]' % (input_filepath, page - 1) # Specify the file format next to the output filename output_filepath = u'%s:%s' % (file_format, output_filepath) command = [] command.append(unicode(GM_PATH)) command.append(u'convert') command.extend(unicode(GM_SETTINGS).split()) command.append(unicode(input_arg)) if arguments: command.extend(arguments) command.append(unicode(output_filepath)) proc = subprocess.Popen(command, close_fds=True, stderr=subprocess.PIPE, stdout=subprocess.PIPE) return_code = proc.wait() if return_code != 0: #Got an error from convert program error_line = proc.stderr.readline() if (CONVERTER_ERROR_STRING_NO_DECODER in error_line) or (CONVERTER_ERROR_STARTS_WITH in error_line): #Try to determine from error message which class of error is it raise UnknownFileFormat else: raise ConvertError(error_line)