0

如果我说文件调用 '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

你知道为什么吗?

4

1 回答 1

0

我已将此添加到 imageColor.rb:

source_file  = [sourceFile,".png"].join("")
target_file  = [targetFile,".png"].join("")        
source_color = [sourceColor].join("")        
target_color = [targetColor].join("")
于 2013-11-13T17:03:05.293 回答