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