如果我说文件调用 'mask.png' 比这段代码有效:
#imageColor.rb
require 'RMagick'
include Magick
module Sass::Script::Functions
def imagetest(sourceFile, targetFile, sourceColor, targetColor)
sources = Image.read('mask.png')
target = sources[0].opaque('black', 'blue')
target.write('test.png')
Sass::Script::String.new("#00ff00")
end
end
#_imageColor.scss
@mixin image-color($source, $target, $sourceColor, $targetColor)
{
color: imagetest($source, $target, $sourceColor, $targetColor);
}
#ie.scss
@import "theme/default/ie/ie";
@import "imageColor";
body {
@include image-color('mask.png', 'test.png', '#000000', '#ff0000');
}
如果我在方法 image-color (在 ie.scss 中)中说文件调用“mask.png”,则此代码不起作用:
#imageColor.rb
require 'RMagick'
include Magick
module Sass::Script::Functions
def imagetest(sourceFile, targetFile, sourceColor, targetColor)
sources = Image.read(sourceFile)
target = sources[0].opaque(sourceColor, targetColor)
target.write(targetFile)
Sass::Script::String.new("#00ff00")
end
end
错误:
unable to open image `"mask.png"': No such file or directory
你知道为什么吗?