Package: pelican-photos
Photos: A Plugin for PelicanUse Photos to add a photo or a gallery of photos to an article, or to include photos in the body text. Photos are kept separately, as an organized library of high resolution photos, and resized as needed.InstallationThis plugin can be installed via:python -m pip install pelican-photosThe plug-in requiresPillow: the Python Imaging Library and optionallyPiexif, whose installation are outside the scope of this document.UsageThe plug-in resizes the referred photos, and generates thumbnails for galleries and associated photos, based on the following configuration and default values:PHOTO_LIBRARY = "~/Pictures":	Absolute path to the folder where the original photos are kept, organized in sub-folders.PHOTO_GALLERY = (1024, 768, 80):	For photos in galleries, maximum width and height, plus JPEG quality as a percentage. This would typically be the size of the photo displayed when the reader clicks a thumbnail.PHOTO_ARTICLE = (760, 506, 80):	For photos associated with articles, maximum width, height, and quality. The maximum size would typically depend on the needs of the theme. 760px is suitable for the themenotmyidea.PHOTO_THUMB = (192, 144, 60):	For thumbnails, maximum width, height, and quality.PHOTO_SQUARE_THUMB = False:	Crops thumbnails to make them square.PHOTO_RESIZE_JOBS = 5: Number of parallel resize jobs to be run. Defaults to 1.-1= Do not use the Python multiprocessing module and enable additional debugging0= Try to detect cpu count and startCPU_COUNT + 1processes1= Use 1 process2= Use 2 processes3= Use 3 processes...PHOTO_WATERMARK = True: Adds a watermark to all photos in articles and pages. Defaults to using your site name.PHOTO_WATERMARK_TEXT' = SITENAME: Allow the user to change the watermark text or remove it completely. By default it usesSourceCodePro-Boldas the font.PHOTO_WATERMARK_IMG = '': Allows the user to add an image in addition to or as the only watermark. Set the variable to the location.The following features require the piexif libraryPHOTO_EXIF_KEEP = True: Keeps the exif of the input photo.PHOTO_EXIF_REMOVE_GPS = True: Removes any GPS information from the files exif data.PHOTO_EXIF_COPYRIGHT = 'COPYRIGHT': Attaches an author and a license to the file. Choices include:
-COPYRIGHT: Copyright
-CC0: Public Domain
-CC-BY-NC-ND: Creative Commons Attribution-NonCommercial-NoDerivatives
-CC-BY-NC-SA: Creative Commons Attribution-NonCommercial-ShareAlike
-CC-BY: Creative Commons Attribution
-CC-BY-SA: Creative Commons Attribution-ShareAlike
-CC-BY-NC: Creative Commons Attribution-NonCommercial
-CC-BY-ND: Creative Commons Attribution-NoDerivativesPHOTO_EXIF_COPYRIGHT_AUTHOR = 'Your Name Here': Adds an author name to the photo's exif and copyright statement. Defaults toAUTHORvalue from thepelicanconf.pyPHOTO_INLINE_GALLERY_ENABLED: Enable inline gallery processing. (Default: False)PHOTO_INLINE_GALLERY_PATTERN: The pattern to look for. Thegallery_nameis used to find the right gallery.Defaults:r"gallery::(?P<gallery_name>[/{}\w_-]+)"PHOTO_INLINE_GALLERY_TEMPLATE: Template to render the inline gallery.Default:"inline_gallery"PHOTO_DEFAULT_IMAGE_OPTIONS: Default keyword options to pass to the PIL.Image.save() function.
You can find all available options in thePillow: Image file formatssection.Defaults:{"jpeg":{"optimize":True}}PHOTO_RESULT_IMAGE_AVERAGE_COLOR = False: Calculate the average color for an result image. This can be used to provide a default background color while using lazy loading.PHOTO_PROFILING_ENABLED = False: Enable profiling of function calls and measure the time. You have to run pelican in debug mode to see the results.The plug-in automatically resizes the photos and publishes them to the following output folder:./output/photosWARNING:The plug-in can take hours to resize 40,000 photos, therefore, photos and thumbnails are only generated once. Clean the output folders to regenerate the resized photos again.How to useMaintain an organized library of high resolution photos somewhere on disk, using folders to group related images. The default path~/Picturesis convenient for Mac OS X users.To create a gallery of photos, add the metadata fieldgallery: {photo}folderto an article. To simplify the transition from the plug-in Gallery, the syntaxgallery: {filename}folderis also accepted.You can now have multiple galleries. The galleries need to be seperated by a comma in the metadata field. The syntax is gallery:{photo}folder, {photo}folder2. You can also add titles to your galleries. The syntax is:{photo}folder, {photo}folder2{This is a title}. Using the following example the first gallery would have the title of the folder location and the second would have the titleThis is a tile.To use an image in the body of the text, just use the syntax{photo}folder/image.jpginstead of the usual{filename}/images/image.jpg.To use an image in the body of the text, which can be used withLightboxjust use the syntax{lightbox}folder/image.jpg. For use with other implementations, the gallery and caption attribute names can be set withPHOTO_LIGHTBOX_GALLERY_ATTRandPHOTO_LIGHTBOX_CAPTION_ATTR.To associate an image with an article, add the metadata fieldimage: {photo}folder/image.jpgto an article. Use associated images to improve navigation. For compatibility, the syntaximage: {filename}/images/image.jpgis also accepted.Exif, Captions, and BlacklistsFolders of photos may optionally have three text files, where each line describes one photo. You can use the#to comment out a line. Generating these optional files is left as an exercise for the reader (but consider using Phil Harvey'sexiftool). See below for one method of extracting exif data.exif.txt:	Associates compact technical information with photos, typically the camera settings. For example:best.jpg: Canon EOS 5D Mark II - 20mm f/8 1/250s ISO 100
night.jpg: Canon EOS 5D Mark II - 47mm f/8 5s ISO 100
# new.jpg: Canon EOS 5D Mark II - 47mm f/8 5s ISO 100captions.txt:	Associates comments with photos. For example:best.jpg: My best photo ever! How lucky of me!
night.jpg: Twilight over the dam.
# new.jpg: My new photo blog entry is not quite ready.blacklist.txt: Skips photos the user does not want to include. For example:this-file-will-be-skipped.jpg
this-one-will-be-skipped-too.jpg
# but-this-file-will-NOT-be-skipped.jpg
this-one-will-be-also-skipped.jpgHere is an example Markdown article that shows the four use cases:title: My Article
gallery: {photo}favorite
image: {photo}favorite/best.jpg

Here are my best photos, taken with my favorite camera:
![]({photo}mybag/camera.jpg).
![]({lightbox}mybag/flash.jpg).The default behavior of the Photos plugin removes the exif information from the file. If you would like to keep the exif information, you can install thepiexiflibrary for python and add the following settings to keep some or all of the exif information. This feature is not a replacement for theexif.txtfeature but in addition to that feature. This feature currently only works with jpeg input files.How to change the Jinja templatesThe plugin provides the following variables to your templates:article.photo_image:	For articles with an associated photo, a tuple with the following information:The filename of the original photo.The output path to the generated photo.The output path to the generated thumbnail.For example, modify the templatearticle.htmlas shown below to display the associated image before the article content:<divclass="entry-content">{% if article.photo_image %}<imgsrc="{{ SITEURL }}/{{ article.photo_image[1] }}"/>{% endif %}
	{% include 'article_infos.html' %}
	{{ article.content }}</div><!-- /.entry-content -->article.photo_gallery:	For articles with a gallery, a list of the photos in the gallery. Each item in the list is a tuple with five elements:The title of the galleryThe filename of the original photo.The output path to the generated photo.The output path to the generated thumbnail.The EXIF information of the photo, as read from the fileexif.txt.The caption of the photo, as read fromcaptions.txt.For example, add the following to the templatearticle.htmlto add the gallery as the end of the article:{% if article.photo_gallery %}<divclass="gallery">{% for title, gallery in article.photo_gallery %}<h1>{{ title }}</h1>{% for name, photo, thumb, exif, caption in gallery %}<ahref="{{ SITEURL }}/{{ photo }}"title="{{ name }}"exif="{{ exif }}"caption="{{ caption }}"><imgsrc="{{ SITEURL }}/{{ thumb }}"></a>{% endfor %}
		{% endfor %}</div>{% endif %}For example, add the following to the templateindex.html, inside theentry-content, to display the thumbnail with a link to the article:{% if article.photo_image %}<ahref="{{ SITEURL }}/{{ article.url }}"><imgsrc="{{ SITEURL }}/{{ article.photo_image[2] }}"style="display: inline; float: right; margin: 2px 0 2ex 4ex;"/></a>{% endif %}How to make the gallery lightboxThere are several JavaScript libraries that display a list of images as a lightbox. The example below usesMagnific Popup, which allows the more complex initialization needed to display both the filename, the compact technical information, and the caption. The solution would be simpler if photos did not show any extra information.Copy the filesmagnific-popup.cssandmagnific-popup.jsto the root of your Pelican template.Add the following to the templatebase.html, inside the HTMLheadtags:{% if (article and article.photo_gallery) or (articles_page and articles_page.object_list[0].photo_gallery) %}<linkrel="stylesheet"href="{{ SITEURL }}/{{ THEME_STATIC_DIR }}/magnific-popup.css">{% endif %}Add the following to the templatebase.html, before the closing HTML</body>tag:{%if(articleandarticle.photo_gallery)or(articles_pageandarticles_page.object_list[0].photo_gallery)%}<!--jQuery1.7.2+orZepto.js1.0+--><scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script><!--MagnificPopupcoreJSfile--><scriptsrc="{{ SITEURL }}/{{ THEME_STATIC_DIR }}/magnific-popup.js"></script><script>$('.gallery').magnificPopup({delegate:'a',type:'image',gallery:{enabled:true,navigateByImgClick:true,preload:[1,2]},image:{titleSrc:function(item){if(item.el.attr('caption')&&item.el.attr('exif')){return(item.el.attr('caption').replace(/\\n/g,'<br />')+'<small>'+item.el.attr('title')+' - '+item.el.attr('exif')+'</small>');}returnitem.el.attr('title')+'<small>'+item.el.attr('exif')+'</small>';}}});</script>{%endif%}How to make a Bootstrap CarouselIf you are using bootstrap, the following code is an example of how one could create a carousel.{% if article.photo_gallery %}
  {% for title, gallery in article.photo_gallery %}<h1>{{ title }}</h1><divid="carousel-{{ loop.index }}"class="carousel slide"><olclass="carousel-indicators">{% for i in range(0, gallery|length) %}<lidata-target="#carousel-{{ loop.index }}"data-slide-to="{{ i }}"{%ifi==0%}class="active"{%endif%}></li>{% endfor %}</ol><divclass="carousel-inner">{% for name, photo, thumb, exif, caption in gallery %}
          {% if loop.first %}<divclass="item active">{% else %}<divclass="item">{% endif %}<imgsrc="{{ SITEURL }}/{{ photo }}"exif="{{ exif }}"alt="{{ caption }}"><divclass="carousel-caption"><h5>{{ caption }}</h5></div><!-- carousel-caption --></div><!-- item -->{% endfor %}</div><!-- carousel-inner --><aclass="left carousel-control"href="#carousel-{{ loop.index }}"data-slide="prev"><spanclass="glyphicon glyphicon-chevron-left"></span></a><aclass="right carousel-control"href="#carousel-{{ loop.index }}"data-slide="next"><spanclass="glyphicon glyphicon-chevron-right"></span></a></div><!-- closes carousel-{{ loop.index }} -->{% endfor %}
{% endif %}Exiftool exampleYou can add the following stanza to your fab file if you are usingfabricto generate the appropriate text files for your galleries. You need to set the location ofExiftoolcontrol files.defphoto_gallery_gen(location):"""Create gallery metadata files."""local_path=os.getcwd()+'LOCATION OF YOUR EXIF CONTROL FILES'withlcd(location):local("exiftool -p{fmt_path}/exif.fmt . > exif.txt".format(fmt_path=local_path))local("exiftool -p{fmt_path}/captions.fmt . > captions.txt".format(fmt_path=local_path))captions.fmtexample file$FileName: $Descriptionexif.fmtexample file$FileName: $CreateDate - $Make $Model Stats:(f/$Aperture, ${ShutterSpeed}s, ISO $ISO Flash: $Flash) GPS:($GPSPosition $GPSAltitude)Known use casespxquim.ptuses Photos and the plug-in Sub-parts to publish 600 photo galleries with 40,000 photos. Photos keeps the high-resolution photos separate from the site articles.pxquim.comuses sub-parts to cover conferences, where it makes sense to have a sub-part for each speaker.AlternativesGallery
:	Galleries are distinct entities, without the organizational capabilities of articles. Photos must be resized separately, and must be kept with the source of the blog. Gallery was the initial inspiration for Photos.Image_process
:	Resize and process images in the article body in a more flexible way (based on the CSS class of the image), but without the ability to create galleries. The source photos must be kept with the source of the blog.ContributingContributions are welcome and much appreciated. Every little bit helps. You can contribute by improving the documentation, adding missing features, and fixing bugs. You can also help out by reviewing and commenting onexisting issues.To start contributing to this plugin, review theContributing to Pelicandocumentation, beginning with theContributing Codesection.LicenseThis project is licensed under the AGPL-3.0 license.