Warning, /documentation/digikam-doc/post_processing/html_gallery.rst is written in an unsupported language. File is not indexed.

0001 .. meta::
0002    :description: The digiKam HTML Gallery
0003    :keywords: digiKam, documentation, user manual, photo management, open source, free, learn, easy, html, gallery
0004 
0005 .. metadata-placeholder
0006 
0007    :authors: - digiKam Team
0008 
0009    :license: see Credits and License page for details (https://docs.digikam.org/en/credits_license.html)
0010 
0011 .. _html_gallery:
0012 
0013 HTML Gallery
0014 ============
0015 
0016 .. contents::
0017 
0018 Overview
0019 --------
0020 
0021 The HTML Gallery is a tool for exporting a set of Albums or images to a HTML page.
0022 
0023 This powerful tool can export your Albums into a HTML compliant web image gallery. You can easily select the Images or the Albums to export in an HTML page and set many designs and parameters for the HTML rendering. UTF-8 encoding is used for the best internationalization.
0024 
0025 Using the Wizard
0026 ----------------
0027 
0028 .. figure:: images/html_gallery_page1.webp
0029     :alt:
0030     :align: center
0031 
0032     The HTML Gallery Page Selection Mode
0033 
0034 To launch the tool, uses :menuselection:`Tools --> Create Html gallery` :kbd:`Ctrl+Alt+Shift+H` menu entry, or the corresponding icon from the **Tools** tab in Right Sidebar. The tool will displays a view to select the contents to export: from current items selection, or from a list of albums. The **Albums** selection mode allows you to select items from Albums that you want to export to HTML. Just check the respective Albums displayed with hierarchical nesting. On the next three tabs **Tags**, **Searches**, and **Labels** you can refine your selection using tags, labels, or previous search results in digiKam. 
0035 
0036 .. figure:: images/html_gallery_page2.webp
0037     :alt:
0038     :align: center
0039 
0040     The HTML Gallery Page to Select Items
0041 
0042 Next step is to select a **Theme** to generate the gallery.
0043 
0044 .. figure:: images/html_gallery_page3.webp
0045     :alt:
0046     :align: center
0047 
0048     The HTML Gallery Page to Select Theme
0049 
0050 Depending on the chosen theme you may have additional options to fine-tune the appearance of the gallery.
0051 
0052 The next screenshot shows the theme parameters configuration (here the **Classic** theme for example).
0053 
0054 .. figure:: images/html_gallery_page4.webp
0055     :alt:
0056     :align: center
0057 
0058     The HTML Gallery Page to Tune Theme Parameters
0059 
0060 For all selected themes you can adjust the settings for the images and thumbnails in the gallery.
0061 
0062 .. figure:: images/html_gallery_page5.webp
0063     :alt:
0064     :align: center
0065 
0066     The HTML Gallery Page to Tune Images and Thumbnail Properties
0067 
0068 In the Full Image section you can either save modified images or Use original image.
0069 
0070 For modified images you can select as output format JPEG (smallest file-size, but lossy) and PNG (lossless and free license) and set specific image compression features. If disk space is of concern check the target image compression and lower the compression level from the host application default value.
0071 
0072 Checking the Max. size box you can fix the maximum target image size (in pixels) with the spin-box at the right. Images bigger than this value will be scaled down to it, but smaller images will not be modified.
0073 
0074 .. note::
0075 
0076     If JPEG file format is selected for target resizing images, all Exif information will be preserved from the original JPEG files.
0077 
0078 The Thumbnails section allows to set the Format, Quality and Size for the thumbnails in the gallery.
0079 
0080 .. figure:: images/html_gallery_page6.webp
0081     :alt:
0082     :align: center
0083 
0084     The HTML Gallery Page to Configure the Output
0085 
0086 This page defines the settings of where and how to store the gallery with all its associated images. Select a folder or add a new folder with write access where you want the gallery to be written to. Two sub-folders with the name of your album folder and the theme name will be created containing everything.
0087 
0088 A progress dialog giving a feedback indicate to user. Press Cancel button during this stage if you want abort the process.
0089 
0090 .. figure:: images/html_gallery_page7.webp
0091     :alt:
0092     :align: center
0093 
0094     The HTML Gallery Page to Show Progress While Generating the Gallery
0095 
0096 Finally, the HTML gallery generated is displayed in a browser.
0097 
0098 .. figure:: images/html_gallery_page8.webp
0099     :alt:
0100     :align: center
0101 
0102     The Browser Displaying the HTML Gallery at end
0103 
0104 .. _htmlgallery_newtheme:
0105 
0106 Creating a New Theme
0107 --------------------
0108 
0109 The HTML Gallery tool can easily be themed to produce very different sites. This chapter explains how to create themes.
0110 
0111 Getting Started
0112 ~~~~~~~~~~~~~~~
0113 
0114 A theme is a folder which contains at least two files:
0115 
0116     - A **Desktop file** describing the theme.
0117     - A :file:`template.xsl` file to generate the HTML files.
0118 
0119 When the tool is running, it does the following:
0120 
0121     - Create an output folder.
0122     - For each image collection:
0123 
0124         - Create a folder.
0125         - Generate thumbnails (square by default).
0126         - Generate full images.
0127         - Optionally copy original images.
0128 
0129     - Copy the theme folder to the output folder.
0130     - Generate an XML file describing the image collections: :file:`gallery.xml`.
0131     - Generate the HTML files by applying :file:`template.xsl` to :file:`gallery.xml`.
0132 
0133 The Desktop File
0134 ~~~~~~~~~~~~~~~~
0135 
0136 The desktop file describes the theme. The information it contains is used in the theme selection page of the tool.
0137 
0138 It's an **INI** file and it looks like this:
0139 
0140 .. code-block:: ini
0141 
0142     [Desktop Entry]
0143     Type=Theme
0144     Name=Hello World
0145     Comment=A demonstration theme
0146 
0147     [X-HTMLGallery Author]
0148     Name=The Author
0149     Url=http://example.com/themes/helloworld
0150 
0151     [X-HTMLGallery Preview]
0152     Name=Preview's Caption
0153     Url=preview.png
0154 
0155 A desktop file format is used to facilitate entry translations. If you look at the desktop file for one of the themes shipped with the tool, you will find something like this:
0156 
0157 .. code-block:: ini
0158 
0159     [Desktop Entry]
0160     Name=Simple
0161     Name[br]=Eeun
0162     Name[cs]=JednoduchĂ˝
0163     Name[cy]=Syml
0164     Name[da]=Simpel
0165     ...
0166 
0167 The nice thing is that when your theme get integrated into HTML Gallery default themes, translators will internationalize the desktop file for you.
0168 
0169 The **image preview** file used to illustrate the Theme in the wizard will be placed in the root theme folder.
0170 
0171 Creating new Theme from Another One
0172 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0173 
0174 The easiest way to get started is to copy one theme and modify it. Folder can be found usually under **Linux** at :file:`/usr/share/apps/digikam/themes/`. Writing in this folder requires root access, so we will not create our theme there, instead do the following from a console:
0175 
0176 Create a theme folder in your home directory:
0177 
0178 .. code-block:: shell
0179 
0180     mkdir -p ~/.local/share/digikam/themes/
0181 
0182 - Go to this directory:
0183 
0184 .. code-block:: shell
0185 
0186     cd ~/.local/share/digikam/themes/
0187 
0188 Copy the **snow** theme to this folder, under a new name **snow2**:
0189 
0190 .. code-block:: shell
0191 
0192     cp -r /usr/share/apps/digikam/themes/snow snow2
0193 
0194 Rename the desktop file accordingly:
0195 
0196 .. code-block:: shell
0197 
0198     cd snow2
0199     mv snow.desktop snow2.desktop
0200 
0201 Edit :file:`snow2.desktop` to remove all the **Name[...]** entries and replace **Name=Snow** with **Name=Snow 2**.
0202 
0203 You are done, you can now open digiKam and start the HTML Gallery tool, the **Snow 2** theme should appear in the theme list.
0204 
0205 Generating HTML Using XSL Rules
0206 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0207 
0208 The :file:`template.xsl` file is responsible for generating the HTML files from the :file:`gallery.xml` file. It's a standard ini-style file and looks like this:
0209 
0210 .. code-block:: xml
0211 
0212      <?xml version="1.0" encoding="UTF-8"?>
0213      <collections>
0214       <collection>
0215        <name>Name of first collection</name>
0216        <fileName>collection_folder</fileName>
0217        <comment>Collection comment</comment>
0218        <image>
0219         <title>Image Title</title>
0220         <description>Image Description</description>
0221         <date>2009-08-27T09:53:26</date>
0222         <full fileName="pict1279.jpeg" height="450" width="600"/>
0223         <thumbnail fileName="thumb_pict1279.jpeg" height="80" width="80"/>
0224         <!-- If there is an original image, you will get the 'original' tag -->
0225         <original fileName="original_pict1279.jpeg" height="3000" width="4000"/>
0226 
0227        </image>
0228        <image>
0229         <title>Image Title</title>
0230         <date>2009-08-27T09:55:33</date>
0231         <description>Image Description</description>
0232         <full fileName="pict1280.jpeg" height="450" width="600"/>
0233         <thumbnail fileName="thumb_pict1280.jpeg" height="80" width="80"/>
0234         <original fileName="original_pict1279.jpeg" height="3000" width="4000"/>
0235        </image>
0236        ...
0237       </collection>
0238 
0239       <collection>
0240        <name>Name of second collection</name>
0241        ...
0242       </collection>
0243      </collections>
0244 
0245 We won't explain XSLT syntax here, you should be able to find the documentation you need on the Internet. We recommend to learn XSLT with the `XSLT tutorial here <https://www.w3schools.com/xsl>`_.
0246 
0247 It's worth noting nevertheless that you can make use of `EXSLT <https://www.exslt.org>`_, a set of extensions to XSLT. In particular, the `exslt:document element <https://www.exslt.org/exsl/elements/document>`_  is extremely useful because it allows you to generate multiple documents from the same file.
0248 
0249 HTML Gallery tool imposes no constraint on the organization of HTML files. You can generate one file per image, or only one per collection. One could imagine a theme which would only contains one HTML file and uses JavaScript to show the different images, there is already one theme using frames, you can even generate CSS files on the fly if you want to.
0250 
0251 About Translations
0252 ~~~~~~~~~~~~~~~~~~
0253 
0254 You should not **hardcode** any text in the template, instead you should use the **i18n parameters**. For example instead of using this:
0255 
0256 .. code-block:: xml
0257 
0258     <a href="previous">Previous</a>
0259     | <a href="next">Next</a>
0260 
0261 Do this:
0262 
0263 .. code-block:: xml
0264 
0265     <a href="previous"><xsl:value-of select="$i18nPrevious"/></a>
0266     | <a href="next"><xsl:value-of select="$i18nNext"/></a>
0267 
0268 It's quite a lot more verbose, but this way your user will get localized HTML output.
0269 
0270 If you want to use **i18n parameters** in attributes, do it like this:
0271 
0272 .. code-block:: xml
0273 
0274     <a href="previous" title="{$i18nPrevious}"><img src="previous.png"/></a>
0275     | <a href="next" title="{$i18nNext}"><img src="next.png"/></a>
0276 
0277 For now, the available general **i18n parameters** are:
0278 
0279     - i18nPrevious
0280     - i18nNext
0281     - i18nCollectionList
0282     - i18nOriginalImage
0283     - i18nUp
0284 
0285 And for the **image properties** they are:
0286 
0287     - i18nexifimagemake ("Make")
0288     - i18nexifimagemodel ("Model")
0289     - i18nexifimageorientation ("Image Orientation")
0290     - i18nexifimagexresolution ("Image X Resolution")
0291     - i18nexifimageyresolution ("Image Y Resolution")
0292     - i18nexifimageresolutionunit ("Image Resolution Unit")
0293     - i18nexifimagedatetime ("Image Date Time")
0294     - i18nexifimageycbcrpositioning ("YCBCR Positioning")
0295     - i18nexifphotoexposuretime ("Exposure Time")
0296     - i18nexifphotofnumber ("F Number")
0297     - i18nexifphotoexposureprogram ("Exposure Index")
0298     - i18nexifphotoisospeedratings ("ISO Speed Ratings")
0299     - i18nexifphotoshutterspeedvalue ("Shutter Speed Value")
0300     - i18nexifphotoaperturevalue ("Aperture Value")
0301     - i18nexifphotofocallength ("Focal Length")
0302 
0303 If you need more i18n parameters, please report this wish to the `Project Team <https://www.digikam.org/support/>`_.
0304 
0305 Images and CSS Files
0306 ~~~~~~~~~~~~~~~~~~~~
0307 
0308 You are free to use images, CSS files or other files in your theme. Just put them in the theme folder and the tool will copy them in the output folder.
0309 
0310 Original Images
0311 ```````````````
0312 
0313 As explained before, if the user selects the option **Include original images**, the :file:`gallery.xml` file will contain **<original />** tags. If this tag is present, the image page should contain a link to download the original image.
0314 
0315 Here is an example:
0316 
0317 .. code-block:: xml
0318 
0319     <xsl:if test="original/@fileName != ''">
0320           <p>
0321                <a href="{original/@fileName}"><xsl:value-of select="$i18nOriginalImage"/></a>
0322           </p>
0323      </xsl:if>
0324 
0325 Non-Square Thumbnails
0326 `````````````````````
0327 
0328 By default, thumbnails are cropped so that they are square-shaped and all have an identical size. This makes it easier to create the HTML/CSS style. However, if your theme is ready to cope with thumbnails of different sizes, add this snippet to your desktop file:
0329 
0330 .. code-block:: ini
0331 
0332     [X-HTMLGallery Options]
0333     Allow-non-square-thumbnails=true
0334 
0335 The user will then be able to select whether squares should or should not be square. For non-square thumbnails, the specified thumbnail size becomes the size of the larger side of the thumbnail.
0336 
0337 Theme Parameters
0338 ~~~~~~~~~~~~~~~~
0339 
0340 You might want to provide a way for the user to customize your theme, for example you could provide a few alternative CSS files, or let the user customize the background color. This is easy to do.
0341 
0342 Declaring a Parameter
0343 `````````````````````
0344 
0345 First, you need to declare your parameter. Edit your desktop file and add something like this:
0346 
0347 .. code-block:: ini
0348 
0349     [X-HTMLGallery Parameter bgColor]
0350     Name=Background Color
0351     Type=color
0352     Default=#123456
0353 
0354 Now start the tool and select your theme, after pressing next, you should see an option page with a color button initialized to the **#123456** color.
0355 
0356 Using Parameter Value
0357 `````````````````````
0358 
0359 In :file:`template.xsl`, you can get the value of your parameter like this:
0360 
0361 .. code-block:: xml
0362 
0363     <xsl:value-of select="$bgColor"/>
0364 
0365 To change the background color of the **body** tag, you would write something like this:
0366 
0367 .. code-block:: xml
0368 
0369     <body bgcolor="{$bgColor}">
0370     ...
0371     </body>
0372 
0373 Parameter Reference
0374 ```````````````````
0375 
0376 Here is a more complete description of the way to declare parameters. A parameter is declared by a section named **X-HTMLGallery Parameter someName**. **someName** should be replaced with the name you want to use in :file:`template.xsl`.
0377 
0378 - The **Name** key defines the text which will be shown in the option page. Since this is a desktop file, it can be translated like the other keys.
0379 
0380 - The **Type** key defines the type of the parameter. At the time of this writing it can be one of:
0381 
0382     - caption
0383     - string
0384     - color
0385     - list
0386     - int
0387 
0388 - The **Default** key defines the default value of the parameter.
0389 
0390 List Parameter Keys
0391 ```````````````````
0392 
0393 A list parameter lets the user select an item from a list. To declare the available items, you must use two sets of keys: **Value-N** and **Caption-N**, where **N** is the position of the item, starting from **0**.
0394 
0395 **Value-N** is the internal value of the item. This is the value which will be set to the parameter.
0396 
0397 **Caption-N** is the displayed value of the item. This is the text which will be shown in the list.
0398 
0399 Here is an example: the **style** parameter from the **Simple** theme:
0400 
0401 .. code-block:: ini
0402 
0403      [X-HTMLGallery Parameter style]
0404      Name=Style
0405      Type=list
0406      Default=natural.css
0407      Value-0=natural.css
0408      Caption-0=Natural
0409      Value-1=dark.css
0410      Caption-1=Dark
0411 
0412 As you can see, the user will be able to choose either **Natural** or **Dark**. Depending on the user choice, **<xsl:value-of select='$style'/>** will expand to either :file:`natural.css` or :file:`dark.css`.
0413 
0414 Int Parameter Keys
0415 ``````````````````
0416 
0417 An int parameter lets the user select an integer using a spin-box. In addition to the default value, you can define the minimum and maximum values, using the **Min** and **Max** keys.
0418 
0419 Here is an example:
0420 
0421 .. code-block:: ini
0422 
0423      [X-HTMLGallery Parameter size]
0424      Name=Size
0425      Type=int
0426      Default=12
0427      Min=4
0428      Max=28
0429 
0430 String and Caption Parameter Keys
0431 `````````````````````````````````
0432 
0433 A string parameter lets the user enter a single string to set configuration rules for example. A caption parameter lets the user enter a multi-string with spell-checking support to set a **Description** or a **Title**.
0434 
0435 Final Words
0436 ~~~~~~~~~~~
0437 
0438 This is the end of this chapter, now is the time for you to get creative and add new themes.
0439 
0440 When you are done, do not hesitate to propose your work for an official integration in digiKam, to see your new theme included in the official list. See the `Contribute page <https://www.digikam.org/contribute/>`_ from the digiKam project web-site for details.
0441