Skip to content

Commit

Permalink
Fix bug where original.path was absolute
Browse files Browse the repository at this point in the history
  • Loading branch information
wildlyinaccurate committed Sep 25, 2016
1 parent 34d47b8 commit 4bf8cc7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
4 changes: 2 additions & 2 deletions lib/jekyll/responsive_image/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ def render_responsive_image(context, attributes)
site = context.registers[:site]
config = make_config(site)

source_image_path = site.in_source_dir(attributes['path'].to_s)
image = ImageProcessor.process(source_image_path, config)
absolute_image_path = site.in_source_dir(attributes['path'].to_s)
image = ImageProcessor.process(absolute_image_path, attributes['path'], config)
attributes['original'] = image[:original]
attributes['resized'] = image[:resized]

Expand Down
6 changes: 4 additions & 2 deletions lib/jekyll/responsive_image/extra_image_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ def generate(site)
config = make_config(site)

config['extra_images'].each do |pathspec|
Dir.glob(site.in_source_dir(pathspec)) do |path|
result = ImageProcessor.process(path, config)
Dir.glob(site.in_source_dir(pathspec)) do |image_path|
relative_image_path = image_path.sub(/^#{Regexp.escape(image_path)}/, '')

result = ImageProcessor.process(image_path, relative_image_path, config)
result[:resized].each { |image| keep_resized_image!(site, image) }
end
end
Expand Down
12 changes: 6 additions & 6 deletions lib/jekyll/responsive_image/image_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ class ResponsiveImage
class ImageProcessor
include ResponsiveImage::Utils

def process(image_path, config)
raise SyntaxError.new("Invalid image path specified: #{image_path}") unless File.file?(image_path)
def process(absolute_image_path, relative_image_path, config)
raise SyntaxError.new("Invalid image path specified: #{absolute_image_path}") unless File.file?(absolute_image_path)

resize_handler = ResizeHandler.new
img = Magick::Image::read(image_path).first
img = Magick::Image::read(absolute_image_path).first

{
original: image_hash(config['base_path'], image_path, img.columns, img.rows),
original: image_hash(config['base_path'], relative_image_path, img.columns, img.rows),
resized: resize_handler.resize_image(img, config),
}
end

def self.process(image_path, config)
self.new.process(image_path, config)
def self.process(absolute_image_path, relative_image_path, config)
self.new.process(absolute_image_path, relative_image_path, config)
end
end
end
Expand Down

0 comments on commit 4bf8cc7

Please sign in to comment.