Skip to main content

Generation of file previews

Project description

Presentation

This module allows to generate jpeg and pdf preview for virtually any kind of files. It allows to generate preview for a given page. The context of creation of this module (as an example of use context) was for Tracim, a github project (https://github.com/Tracim/tracim) where users can put file on a repository in order to share it with other users. The only way to find a file was with his name. Hence it was decided to generate previews of the files in order to ease the location of one.

Format handled

JPEG

PDF

TEXT

HTML

PNG

&#9745

JPEG

&#9745

BMP

&#9745

GIF

&#9745

PDF

&#9745

Compressed files

&#9745

&#9745

Office files (word, LibreOffice)

&#9745

&#9745

Text

&#9745

Installation

pip install preview_generator


Uses

Getting a preview

from PyPreviewGenerator.manager import *
manager = PreviewManager(path='/home/user/Pictures/')
path_to_file = manager.get_jpeg_preview(
  file_path='/home/user/Pictures/myfile.gif',
  height=100,
  width=100,
)
print('Preview created at path : ', path_to_file)

The preview manager

preview_manager = PreviewManager(cache_path)

args :

cache_path : a String of the path to the directory where the cache file will be stored

returns :

a PreviewManager Object

The builders

Here is the way it is meant to be used

For Office types into PDF :

preview_manager = PreviewManager(cache_path)
preview = preview_manager.get_pdf_preview(file_path,page=page_id)

-> Will create a preview from an office file into a pdf file

args :

file_path : the String of the path where is the file you want to get the preview

page : the page you want to get. If not mentioned all the pages will be returned

returns :

a FileIO stream of bytes of the pdf preview

For images(GIF, BMP, PNG, JPEG) into jpeg:

preview_manager = PreviewManager(cache_path)
preview = preview_manager.get_jpeg_preview(file_path,height=1024,width=526)

-> Will create a preview from an image file into a jpeg file of size 1024 * 526

args :

file_path : the String of the path where is the file you want to get the preview

height : height of the preview in pixels

width : width of the preview in pixels. If not mentioned, width will be the same as height

returns :

a FileIO stream of byte*s of the jpeg preview

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

PyPreviewGenerator-0.1.8.tar.gz (7.5 kB view details)

Uploaded Source

File details

Details for the file PyPreviewGenerator-0.1.8.tar.gz.

File metadata

File hashes

Hashes for PyPreviewGenerator-0.1.8.tar.gz
Algorithm Hash digest
SHA256 ff43020ca6e358b482554d0bffb22a4de03f5378c7cd054e95a6ea23cb9be6d9
MD5 dc7a05e9b759729badfb901ca863c415
BLAKE2b-256 3bd75ed3d880a286ce65b0b296b06321dd36a2e301ffb5c0c72c7bf9ae9896c7

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page