Generation of file previews
Project description
==================================
Preview\_generator's Documentation
==================================
------------
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
--------------
.. raw:: html
<style type="text/css">
.tg {border-collapse:collapse;border-spacing:0;}
.tg td{font-family:Arial, sans-serif;font-size:14px;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;}
.tg th{font-family:Arial, sans-serif;font-size:14px;font-weight:normal;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;}
.tg .tg-baqh{text-align:center;vertical-align:top}
.tg .tg-045v{font-size:100%;font-family:serif !important;;text-align:center;vertical-align:top}
</style>
<table class="tg">
<tr>
<th class="tg-045v"></th>
<th class="tg-baqh">JPEG</th>
<th class="tg-baqh">PDF</th>
<th class="tg-baqh">TEXT</th>
<th class="tg-baqh">HTML</th>
<th class="tg-baqh">JSON<br></th>
</tr>
<tr>
<td class="tg-baqh">PNG</td>
<td class="tg-baqh">☑</td>
<td class="tg-baqh"></td>
<td class="tg-baqh"></td>
<td class="tg-baqh"></td>
<td class="tg-baqh"></td>
</tr>
<tr>
<td class="tg-baqh">JPEG</td>
<td class="tg-baqh">☑</td>
<td class="tg-baqh"></td>
<td class="tg-baqh"></td>
<td class="tg-baqh"></td>
<td class="tg-baqh"></td>
</tr>
<tr>
<td class="tg-baqh">BMP</td>
<td class="tg-baqh">☑</td>
<td class="tg-baqh"></td>
<td class="tg-baqh"></td>
<td class="tg-baqh"></td>
<td class="tg-baqh"></td>
</tr>
<tr>
<td class="tg-baqh">GIF</td>
<td class="tg-baqh">☑</td>
<td class="tg-baqh"></td>
<td class="tg-baqh"></td>
<td class="tg-baqh"></td>
<td class="tg-baqh"></td>
</tr>
<tr>
<td class="tg-baqh">PDF</td>
<td class="tg-baqh">☑</td>
<td class="tg-baqh"></td>
<td class="tg-baqh"></td>
<td class="tg-baqh"></td>
<td class="tg-baqh"></td>
</tr>
<tr>
<td class="tg-baqh">Compressed<br>files<br></td>
<td class="tg-baqh"></td>
<td class="tg-baqh"></td>
<td class="tg-baqh">☑</td>
<td class="tg-baqh">☑</td>
<td class="tg-baqh"></td>
</tr>
<tr>
<td class="tg-baqh">Office files<br>(word, LibreOffice)<br></td>
<td class="tg-baqh">☑</td>
<td class="tg-baqh">☑</td>
<td class="tg-baqh"></td>
<td class="tg-baqh"></td>
<td class="tg-baqh"></td>
</tr>
<tr>
<td class="tg-baqh">Text<br></td>
<td class="tg-baqh"></td>
<td class="tg-baqh"></td>
<td class="tg-baqh">☑</td>
<td class="tg-baqh"></td>
<td class="tg-baqh"></td>
</tr>
<tr>
<td class="tg-baqh"></td>
<td class="tg-baqh"></td>
<td class="tg-baqh"></td>
<td class="tg-baqh"></td>
<td class="tg-baqh"></td>
<td class="tg-baqh"></td>
</tr>
</table>
------------
Installation
------------
`pip install preview_generator`
------------------------------------------------------------------------
----
Uses
----
Getting a preview
-----------------
.. code:: python
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
-------------------
.. code:: python
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 :
===========================
.. code:: python
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:
==========================================
.. code:: python
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*
Preview\_generator's Documentation
==================================
------------
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
--------------
.. raw:: html
<style type="text/css">
.tg {border-collapse:collapse;border-spacing:0;}
.tg td{font-family:Arial, sans-serif;font-size:14px;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;}
.tg th{font-family:Arial, sans-serif;font-size:14px;font-weight:normal;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;}
.tg .tg-baqh{text-align:center;vertical-align:top}
.tg .tg-045v{font-size:100%;font-family:serif !important;;text-align:center;vertical-align:top}
</style>
<table class="tg">
<tr>
<th class="tg-045v"></th>
<th class="tg-baqh">JPEG</th>
<th class="tg-baqh">PDF</th>
<th class="tg-baqh">TEXT</th>
<th class="tg-baqh">HTML</th>
<th class="tg-baqh">JSON<br></th>
</tr>
<tr>
<td class="tg-baqh">PNG</td>
<td class="tg-baqh">☑</td>
<td class="tg-baqh"></td>
<td class="tg-baqh"></td>
<td class="tg-baqh"></td>
<td class="tg-baqh"></td>
</tr>
<tr>
<td class="tg-baqh">JPEG</td>
<td class="tg-baqh">☑</td>
<td class="tg-baqh"></td>
<td class="tg-baqh"></td>
<td class="tg-baqh"></td>
<td class="tg-baqh"></td>
</tr>
<tr>
<td class="tg-baqh">BMP</td>
<td class="tg-baqh">☑</td>
<td class="tg-baqh"></td>
<td class="tg-baqh"></td>
<td class="tg-baqh"></td>
<td class="tg-baqh"></td>
</tr>
<tr>
<td class="tg-baqh">GIF</td>
<td class="tg-baqh">☑</td>
<td class="tg-baqh"></td>
<td class="tg-baqh"></td>
<td class="tg-baqh"></td>
<td class="tg-baqh"></td>
</tr>
<tr>
<td class="tg-baqh">PDF</td>
<td class="tg-baqh">☑</td>
<td class="tg-baqh"></td>
<td class="tg-baqh"></td>
<td class="tg-baqh"></td>
<td class="tg-baqh"></td>
</tr>
<tr>
<td class="tg-baqh">Compressed<br>files<br></td>
<td class="tg-baqh"></td>
<td class="tg-baqh"></td>
<td class="tg-baqh">☑</td>
<td class="tg-baqh">☑</td>
<td class="tg-baqh"></td>
</tr>
<tr>
<td class="tg-baqh">Office files<br>(word, LibreOffice)<br></td>
<td class="tg-baqh">☑</td>
<td class="tg-baqh">☑</td>
<td class="tg-baqh"></td>
<td class="tg-baqh"></td>
<td class="tg-baqh"></td>
</tr>
<tr>
<td class="tg-baqh">Text<br></td>
<td class="tg-baqh"></td>
<td class="tg-baqh"></td>
<td class="tg-baqh">☑</td>
<td class="tg-baqh"></td>
<td class="tg-baqh"></td>
</tr>
<tr>
<td class="tg-baqh"></td>
<td class="tg-baqh"></td>
<td class="tg-baqh"></td>
<td class="tg-baqh"></td>
<td class="tg-baqh"></td>
<td class="tg-baqh"></td>
</tr>
</table>
------------
Installation
------------
`pip install preview_generator`
------------------------------------------------------------------------
----
Uses
----
Getting a preview
-----------------
.. code:: python
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
-------------------
.. code:: python
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 :
===========================
.. code:: python
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:
==========================================
.. code:: python
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file PyPreviewGenerator-0.1.9.tar.gz
.
File metadata
- Download URL: PyPreviewGenerator-0.1.9.tar.gz
- Upload date:
- Size: 7.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 521b0cdea851059c010d03dea3a28a2b4703c5fa40ba2eea340c6c281918f734 |
|
MD5 | 5bf80e02f83cd1a8e57ca9df719492b7 |
|
BLAKE2b-256 | 216a789f5a2b5f2e8388638e04372ecd43d6dd0285cf781039349061f6f62fd2 |