# Buggy code
def create_target_images(self, img, input_path):
    gallery_name = os.path.dirname(img)
    output_gallery = os.path.dirname(
        os.path.join(self.kw["output_folder"], self.site.path("gallery", gallery_name))
    )
    # Do thumbnails and copy originals
    # img is "galleries/name/image_name.jpg"
    # img_name is "image_name.jpg"
    # fname, ext are "image_name", ".jpg"
    # thumb_path is
    # "output/GALLERY_PATH/name/image_name.thumbnail.jpg"
    img_name = os.path.basename(img)
    fname, ext = os.path.splitext(img_name)
    thumb_path = os.path.join(output_gallery, ".thumbnail".join([fname, ext]))
    # thumb_path is "output/GALLERY_PATH/name/image_name.jpg"
    orig_dest_path = os.path.join(output_gallery, img_name)
    yield utils.apply_filters(
        {
            "basename": self.name,
            "name": thumb_path,
            "file_dep": [img],
            "targets": [thumb_path],
            "actions": [
                (self.resize_image, (img, thumb_path, self.kw["thumbnail_size"]))
            ],
            "clean": True,
            "uptodate": [
                utils.config_changed(
                    {1: self.kw["thumbnail_size"]},
                    "nikola.plugins.task.galleries:resize_thumb",
                )
            ],
        },
        self.kw["filters"],
    )

    yield utils.apply_filters(
        {
            "basename": self.name,
            "name": orig_dest_path,
            "file_dep": [img],
            "targets": [orig_dest_path],
            "actions": [
                (self.resize_image, (img, orig_dest_path, self.kw["max_image_size"]))
            ],
            "clean": True,
            "uptodate": [
                utils.config_changed(
                    {1: self.kw["max_image_size"]},
                    "nikola.plugins.task.galleries:resize_max",
                )
            ],
        },
        self.kw["filters"],
    )


# Traceback (IOError)
nikola | /h/@/P/g/msx.github.io ‹master*›> nikola build; nikola deploy; nikola github_deploy
Scanning posts....done!
.  render_galleries:output/en/galleries/demo/index.html
########################################
TaskError - taskid:render_galleries:output/en/galleries/demo/index.html
PythonAction Error
Traceback (most recent call last):
File "/home/@msx/.virtualenvs/nikola/lib/python2.7/site-packages/doit/action.py", line 372, in execute
returned_value = self.py_callable(*self.args, **kwargs)
File "/home/@msx/.virtualenvs/nikola/lib/python2.7/site-packages/nikola/plugins/task/galleries.py", line 533, in render_gallery_index
im = Image.open(thumb)
File "/home/@msx/.virtualenvs/nikola/lib/python2.7/site-packages/PIL/Image.py", line 2248, in open
fp = builtins.open(fp, "rb")
IOError: [Errno 2] No such file or directory: u'output/galleries/demo/tesla4_lg.thumbnail.jpg'



Scanning posts....done!
[2015-05-16T07:25:21Z] INFO: deploy: => preset 'default'
[2015-05-16T07:25:21Z] INFO: deploy: Successful deployment
Scanning posts....done!
.  render_galleries:output/en/galleries/demo/index.html
########################################
TaskError - taskid:render_galleries:output/en/galleries/demo/index.html
PythonAction Error
Traceback (most recent call last):
File "/home/@msx/.virtualenvs/nikola/lib/python2.7/site-packages/doit/action.py", line 372, in execute
returned_value = self.py_callable(*self.args, **kwargs)
File "/home/@msx/.virtualenvs/nikola/lib/python2.7/site-packages/nikola/plugins/task/galleries.py", line 533, in render_gallery_index
im = Image.open(thumb)
File "/home/@msx/.virtualenvs/nikola/lib/python2.7/site-packages/PIL/Image.py", line 2248, in open
fp = builtins.open(fp, "rb")
IOError: [Errno 2] No such file or directory: u'output/galleries/demo/tesla4_lg.thumbnail.jpg'



[2015-05-16T07:25:23Z] ERROR: github_deploy: Build failed, not deploying to GitHub

# Fixed code
def create_target_images(self, img, input_path):
    gallery_name = os.path.dirname(img)
    output_gallery = os.path.dirname(
        os.path.join(
            self.kw["output_folder"], self.site.path("gallery_global", gallery_name)
        )
    )
    # Do thumbnails and copy originals
    # img is "galleries/name/image_name.jpg"
    # img_name is "image_name.jpg"
    # fname, ext are "image_name", ".jpg"
    # thumb_path is
    # "output/GALLERY_PATH/name/image_name.thumbnail.jpg"
    img_name = os.path.basename(img)
    fname, ext = os.path.splitext(img_name)
    thumb_path = os.path.join(output_gallery, ".thumbnail".join([fname, ext]))
    # thumb_path is "output/GALLERY_PATH/name/image_name.jpg"
    orig_dest_path = os.path.join(output_gallery, img_name)
    yield utils.apply_filters(
        {
            "basename": self.name,
            "name": thumb_path,
            "file_dep": [img],
            "targets": [thumb_path],
            "actions": [
                (self.resize_image, (img, thumb_path, self.kw["thumbnail_size"]))
            ],
            "clean": True,
            "uptodate": [
                utils.config_changed(
                    {1: self.kw["thumbnail_size"]},
                    "nikola.plugins.task.galleries:resize_thumb",
                )
            ],
        },
        self.kw["filters"],
    )

    yield utils.apply_filters(
        {
            "basename": self.name,
            "name": orig_dest_path,
            "file_dep": [img],
            "targets": [orig_dest_path],
            "actions": [
                (self.resize_image, (img, orig_dest_path, self.kw["max_image_size"]))
            ],
            "clean": True,
            "uptodate": [
                utils.config_changed(
                    {1: self.kw["max_image_size"]},
                    "nikola.plugins.task.galleries:resize_max",
                )
            ],
        },
        self.kw["filters"],
    )