# Python Watermark
Don't want to release your source code just because you need to add watermarks to your file(s). Python Watermark Allows you to easily add watermarks to PDF, JPG & PNG files with no restrictive licensing
## Installation
Installing the latest PyPI release (recommended)
python3 -m pip install -U pythonwatermark
This will use a pre-built wheel package, the easiest way of installing pythonwatermark.
## Dependencies
pythonwatermark uses two awesome open source python packages to work it's magic they are...
Pillow - https://github.com/python-pillow/Pillow
Like PIL, Pillow is licensed under the open source HPND License
Pypdfium2 - https://github.com/pypdfium2-team/pypdfium2
PDFium and pypdfium2 are available by the terms and conditions of either Apache-2.0 or BSD-3-Clause, at your choice.
These are both fantastic packages and are liberally licensed meaning unlike with other options you don't need to release your source code to the public.
## Usage
Import watermark utils
from pythonwatermark import watermarkutils
Add watermark to file
watermarkutils.put_watermark(inputfile, outputfile, watermark, x=0, y=0, transparency=100, width=None, height=None)
#### Required
inputfile - path as string to PDF, JPG or PNG you wish to add watermark too
outputfile - path as string to where you want output to be saved with either PDF, JPG or PNG file extension.
watermark - path as string to PDF, JPG or PNG file you are using as your watermark
#### Input/Output
inputfile - can be PDF, JPG or PNG.
outputfile - can be PDF, JPG or PNG if the input file is not a PDF. If the input file is a PDF the output file will either be a PDF or you can pass a folder string and the output will be an image per page in JPG format.
watermark - can be PDF, JPG or PNG. Only PNG supports transparency otherwise the background will be included. If you select a multipage PDF as the watermark it will only take the first page as the image/text to be added as a watermark
#### Optional
x - start point along the x axis for the watermark to be inserted, this can be in PX or "left", "centre" or "right" (if not included x defaults to 0)
y - start point along the y axis for the watermark to be inserted, this can be in PX or "top", "middle" or "bottom" (if not included y defaults to 0)
transparency - the transparency/opacity of the inserted watermark in %. 100% is fully visible 1% is barely visible
width/height - Use one or the other to resize the width/height of the watermark keeping the aspect ratio intact
## Advanced
Use getpxsize to return the size in pixels of a file (input file or watermark for custom positioning)
w, h = watermarkutils.getpxsize(inputfile)
If you are resizing a watermark you can also add either the width/height you are resizing to for more accurate placement on the input file
w2, h2 = watermarkutils.getpxsize(watermark, width=300)
w3, h3 = watermarkutils.getpxsize(watermark, height=300)
You can use this to work out watermark placement on your input file
w, h = getpxsize(inputfile)
w2, h2 = getpxsize(watermark)
x = int((w / 2) - (w2 / 2))
y = int((h / 2) - (h2 / 2))
This would provide the X & Y to have the watermark positioned in the centre/middle of the page (though we can also achieve this by passing x="centre" & y="middle")
Raw data
{
"_id": null,
"home_page": "https://github.com/bowespublishing/python-watermark",
"name": "pythonwatermark",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "watermark,pdf watermark,python watermark",
"author": "Bowes Publishing",
"author_email": "",
"download_url": "",
"platform": null,
"description": "# Python Watermark\r\nDon't want to release your source code just because you need to add watermarks to your file(s). Python Watermark Allows you to easily add watermarks to PDF, JPG & PNG files with no restrictive licensing\r\n\r\n## Installation\r\n\r\nInstalling the latest PyPI release (recommended)\r\n\r\n python3 -m pip install -U pythonwatermark\r\n\r\nThis will use a pre-built wheel package, the easiest way of installing pythonwatermark.\r\n\r\n## Dependencies\r\n\r\npythonwatermark uses two awesome open source python packages to work it's magic they are...\r\n\r\nPillow - https://github.com/python-pillow/Pillow\r\n\r\nLike PIL, Pillow is licensed under the open source HPND License\r\n\r\nPypdfium2 - https://github.com/pypdfium2-team/pypdfium2\r\n\r\nPDFium and pypdfium2 are available by the terms and conditions of either Apache-2.0 or BSD-3-Clause, at your choice.\r\n\r\nThese are both fantastic packages and are liberally licensed meaning unlike with other options you don't need to release your source code to the public.\r\n\r\n## Usage\r\nImport watermark utils\r\n\r\n from pythonwatermark import watermarkutils\r\n\r\nAdd watermark to file\r\n\r\n watermarkutils.put_watermark(inputfile, outputfile, watermark, x=0, y=0, transparency=100, width=None, height=None)\r\n \r\n#### Required\r\n \r\ninputfile - path as string to PDF, JPG or PNG you wish to add watermark too\r\n\r\noutputfile - path as string to where you want output to be saved with either PDF, JPG or PNG file extension.\r\n\r\nwatermark - path as string to PDF, JPG or PNG file you are using as your watermark\r\n\r\n#### Input/Output\r\n\r\ninputfile - can be PDF, JPG or PNG.\r\n\r\noutputfile - can be PDF, JPG or PNG if the input file is not a PDF. If the input file is a PDF the output file will either be a PDF or you can pass a folder string and the output will be an image per page in JPG format.\r\n\r\nwatermark - can be PDF, JPG or PNG. Only PNG supports transparency otherwise the background will be included. If you select a multipage PDF as the watermark it will only take the first page as the image/text to be added as a watermark\r\n\r\n#### Optional\r\n\r\nx - start point along the x axis for the watermark to be inserted, this can be in PX or \"left\", \"centre\" or \"right\" (if not included x defaults to 0)\r\n\r\ny - start point along the y axis for the watermark to be inserted, this can be in PX or \"top\", \"middle\" or \"bottom\" (if not included y defaults to 0)\r\n\r\ntransparency - the transparency/opacity of the inserted watermark in %. 100% is fully visible 1% is barely visible\r\n\r\nwidth/height - Use one or the other to resize the width/height of the watermark keeping the aspect ratio intact\r\n\r\n## Advanced\r\n\r\nUse getpxsize to return the size in pixels of a file (input file or watermark for custom positioning)\r\n\r\n w, h = watermarkutils.getpxsize(inputfile)\r\n \r\nIf you are resizing a watermark you can also add either the width/height you are resizing to for more accurate placement on the input file\r\n\r\n w2, h2 = watermarkutils.getpxsize(watermark, width=300)\r\n w3, h3 = watermarkutils.getpxsize(watermark, height=300)\r\n \r\nYou can use this to work out watermark placement on your input file\r\n\r\n w, h = getpxsize(inputfile)\r\n w2, h2 = getpxsize(watermark)\r\n x = int((w / 2) - (w2 / 2))\r\n y = int((h / 2) - (h2 / 2))\r\n \r\nThis would provide the X & Y to have the watermark positioned in the centre/middle of the page (though we can also achieve this by passing x=\"centre\" & y=\"middle\")\r\n",
"bugtrack_url": null,
"license": "",
"summary": "Easily add watermarks to PDF, JPG & PNG files with no restrictive licensing",
"version": "0.0.1",
"split_keywords": [
"watermark",
"pdf watermark",
"python watermark"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "6da9627daf8ec48d56da274d9de52e5c552cc67c373449c57b5fe2cbb525728d",
"md5": "aff037ea50ee1adfa544defdc537f687",
"sha256": "0745ae595ff4b2b3418074c614c1c181eab27794c281b94c23413652f0ec688c"
},
"downloads": -1,
"filename": "pythonwatermark-0.0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "aff037ea50ee1adfa544defdc537f687",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 5734,
"upload_time": "2023-01-20T02:52:16",
"upload_time_iso_8601": "2023-01-20T02:52:16.236863Z",
"url": "https://files.pythonhosted.org/packages/6d/a9/627daf8ec48d56da274d9de52e5c552cc67c373449c57b5fe2cbb525728d/pythonwatermark-0.0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-01-20 02:52:16",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "bowespublishing",
"github_project": "python-watermark",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "pythonwatermark"
}