fixed rmagic
This commit is contained in:
parent
bc13d6aed5
commit
a4861298a7
@ -111,6 +111,7 @@ module Compass
|
||||
end
|
||||
|
||||
def generation_required?
|
||||
puts !File.exists?(filename) || outdated?
|
||||
!File.exists?(filename) || outdated?
|
||||
end
|
||||
|
||||
@ -129,7 +130,6 @@ module Compass
|
||||
@uniqueness_hash
|
||||
end
|
||||
|
||||
# saves the sprite for later retrieval
|
||||
def save!(output_png)
|
||||
saved = output_png.save filename
|
||||
Compass.configuration.run_callback(:sprite_saved, filename)
|
||||
@ -138,31 +138,12 @@ module Compass
|
||||
|
||||
# All the full-path filenames involved in this sprite
|
||||
def image_filenames
|
||||
image_names.map do |image_name|
|
||||
File.join(Compass.configuration.images_path, image_name)
|
||||
end
|
||||
end
|
||||
|
||||
def save!(output_png)
|
||||
saved = output_png.save filename
|
||||
Compass.configuration.run_callback(:sprite_saved, filename)
|
||||
saved
|
||||
end
|
||||
|
||||
# All the full-path filenames involved in this sprite
|
||||
def image_filenames
|
||||
image_names.map do |image_name|
|
||||
File.join(Compass.configuration.images_path, image_name)
|
||||
end
|
||||
@images.map(&:file)
|
||||
end
|
||||
|
||||
# Checks whether this sprite is outdated
|
||||
def outdated?
|
||||
last_update = self.mtime
|
||||
image_filenames.each do |image|
|
||||
return true if File.mtime(image) > last_update
|
||||
end
|
||||
false
|
||||
@images.map(&:mtime).any? { |mtime| mtime > self.mtime }
|
||||
end
|
||||
|
||||
def mtime
|
||||
|
@ -5,19 +5,30 @@ module Compass
|
||||
class ::Magick::Image
|
||||
alias :save :write
|
||||
end
|
||||
|
||||
def composite_images(dest_image, src_image, x, y)
|
||||
width = [src_image.columns + x, dest_image.columns].max
|
||||
height = [src_image.rows + y, dest_image.rows].max
|
||||
image = Magick::Image.new(width, height) {self.background_color = 'none'}
|
||||
image.composite!(dest_image, 0, 0, Magick::CopyCompositeOp)
|
||||
image.composite!(src_image, x, y, Magick::CopyCompositeOp)
|
||||
image
|
||||
end
|
||||
|
||||
# Returns a PNG object
|
||||
def construct_sprite
|
||||
output_png = Magick::Image.new(width, height)
|
||||
output_png.background_color = 'transparent'
|
||||
output_png.format = 'PNG'
|
||||
output_png.background_color = 'none'
|
||||
output_png.format = 'PNG24'
|
||||
images.each do |image|
|
||||
input_png = Magick::Image.read(image.file).first
|
||||
if image.repeat == "no-repeat"
|
||||
output_png.composite!(input_png, image.left, image.top, Magick::CopyCompositeOp)
|
||||
output_png = composite_images(output_png, input_png, image.left, image.top)
|
||||
else
|
||||
x = image.left - (image.left / image.width).ceil * image.width
|
||||
while x < width do
|
||||
output_png.composite!(input_png, x, image.top, Magick::CopyCompositeOp)
|
||||
output_png = composite_images(output_png, input_png, x, image.top)
|
||||
#output_png.composite!(input_png, x, image.top, Magick::CopyCompositeOp)
|
||||
x += image.width
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user