follmann / middleman-favicon-maker

Generate favicon files in various sizes from a base image in your middleman project
MIT License
114 stars 15 forks source link

BUG: Failure when custom output_dir specifies non-existent directory #49

Open vivid-inc opened 6 years ago

vivid-inc commented 6 years ago

favicon-maker fails when output_dir is set to a non-existent path within build/, in this instance build/img/favicon.

    activate :favicon_maker do |f|
    f.output_dir = 'build/img/favicon'

It fails no matter if output_dir is relative or absolute.

According to the build output,build/ and build/img/ directories are created before Middleman comes to favicon-maker, so those directories do exist. The build/img/favicon/ directory is specified only for favicon-maker, and when the Middleman build process comes to the favicon processing step, that directory apparently doesn't exist. This is consistent with my understanding and expectation.

The following build output occurs for each favicon mentioned in the configuration:

convert: unable to open image 'build/img/favicon/apple-touch-icon-180x180-precomposed.png': No such file or directory @ error/blob.c/OpenBlob/3490.
convert: WriteBlob Failed `build/img/favicon/apple-touch-icon-180x180-precomposed.png' @ error/png.c/MagickPNGErrorHandler/1714.
      create  build/img/favicon/apple-touch-icon-180x180-precomposed.png

Representative configuration block from config.rb:

  activate :favicon_maker do |f|
    f.template_dir = File.join(root, 'assets/favicon')

    # NOTE: I observer an identical pattern of failure given either absolute or relative pathing
    f.output_dir = File.join(root, 'build/img/favicon') # Absolute pathing
# OR
    f.output_dir = 'build/img/favicon' # Relative pathing

    require 'fileutils'
    FileUtils.mkdir_p f.output_dir
    f.icons = {
      'favicon-270x270.png' => [
          { icon: "apple-touch-icon-180x180-precomposed.png" }             # Same as apple-touch-icon-57x57.png, for iPhone 6 Plus with @3× display
      ]
    }
  end

favicon-maker functions properly if output_dir is set to dump the favicons in amongst other image resources in the build/img/ directory itself.

Tool versions: Ruby 2.0.0-p648 Middleman 3.3.12 middleman-favicon-maker 3.7