【问题标题】:Ruby: unable to open image `"mask.png"'Ruby:无法打开图像“mask.png”
【发布时间】:2013-11-14 01:03:05
【问题描述】:

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

你知道为什么吗?

【问题讨论】:

  • 如果把图片和scss文件放在同一个文件夹会怎样?
  • ...同样的错误。问题不在路径上。它找到图像,但不想打开它......
  • 尝试只通过不带刻度的 mask.png...看起来它可能会将您的引号括在引号中
  • ...然后出现此错误:“...mage-color(mask": 预期 ")" 后的 CSS 无效,为 ".png, 'test.png...")

标签: ruby image sass compass-sass rmagick


【解决方案1】:

我已将此添加到 imageColor.rb:

source_file  = [sourceFile,".png"].join("")
target_file  = [targetFile,".png"].join("")        
source_color = [sourceColor].join("")        
target_color = [targetColor].join("")

【讨论】:

    猜你喜欢
    • 2020-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-30
    • 2017-04-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多