This has been working for us for years as a quick-and-dirty way to check for duplicate images being uploaded to our Ruby on Rails site:
file.blob.open do |temp_file|
file_data = MiniMagick::Image.open(temp_file.path)
file_data.resize '1024x768'
#md5 = Digest::MD5.hexdigest(file_data.get_pixels.join)
# etc.
end
After recent Rails upgrades (I believe it started around 6.0.4; we're gradually moving to 7.0), this started throwing errors like:
/home/jeff/.rvm/gems/ruby-3.1.2/gems/mini_magick-4.11.0/lib/mini_magick/shell.rb:17:in `run': `convert /tmp/mini_magick20221120-1647726-dit0yb.png -depth 8 RGB:-` failed with error: (MiniMagick::Error) convert-im6.q16: unable to write file `-' # error/constitute.c/WriteImage/1341.
I tracked the problem down to get_pixels. Everything works fine until there, including resizing the image in the previous line. Why do we get this error when calling get_pixels? Why is it trying to write a file when getting the pixels matrix?
Thanks for your help!
Jeff
I'm receiving an error message: error "Windows - No Disk Exception Processing Message 0xc0000013 Unexpected Parameter" when I run - magick Test.png Test.txt
The error message in the DOS window is:
Magick: unable to open image'Test2.txt' : Permission denied # error/blob.c/OpenBlob/3537
I guess I'd describe myself as a lower intermediate programmer. This is my 1st time asking a question here as a new member. The first three times I did this command it worked perfectly. But now I'm getting this error message, and I'm not doing anything different. I really need to get these text files generated from the png files, so I hope that some can help. Probably something very simple, but any advice would be much appreciated.
I use Ruby On Rails 5 and gem sass-rails 5.0
For some reason I get an error message:
wrong number of arguments (1 for 3) for `rgb'
in line number 2 of file app/assets/stylesheets/main.css.scss
$main-color-raw: rgb(0,80,170);
$main-color: rgb($main-color-raw);
$main-color-bright: rgba($main-color-raw, 0.5);
I tried with a hex color value instead of rgb():
$main-color-raw: #0050aa;
But get the same error message.
It looks like the sass-variable $main-color-raw is not evaluated correctly and maybe is the rails-sass gem configuration wrong.
So I added in my config/application.rb
config.sass.preferred_syntax = :scss
config.sass.line_comments = false
config.sass.cache = false
from the rails-sass github documentation page.
But still the same error.
How can I resolve it?
$main-color-raw: rgb(0,80,170);
so in $main-color, you've got:
$main-color: rgb(rgb(0,80,170));
so you are passing only 1 argument to rgb.
You should declare main-color-raw as:
$main-color-raw: 0, 80, 170;
I am trying to use Yolo tiny on Open CV 3.4.1 Can anyone confirm whether it is supported?
I get an error when reading the config file - I am using yolov3-tiny.weights and yolov3-tiny.cfg downloaded from
https://github.com/pjreddie/darknet/blob/master/cfg/yolov3-tiny.cfg
E/cv::error(): OpenCV(3.4.1) Error: Parsing error (Unknown layer type: yolo) in bool cv::dnn::darknet::ReadDarknetFromCfgFile(const char*, cv::dnn::darknet::NetParameter*), file /build/master_pack-android/opencv/modules/dnn/src/darknet/darknet_io.cpp, line 503 07-02 12:10:21.455 31240-31240/ E/org.opencv.dnn: dnn::readNetFromDarknet_10() caught cv::Exception: OpenCV(3.4.1) /build/master_pack-android/opencv/modules/dnn/src/darknet/darknet_io.cpp:503: error: (-212) Unknown layer type: yolo in function bool cv::dnn::darknet::ReadDarknetFromCfgFile(const char*, cv::dnn::darknet::NetParameter*)
As of April 16, yes, it is supported (pull request here). I don't know what your code looks like, but it seems like someone else had the same problem and was able to resolve it. If this doesn't help, feel free to post some code you have and we can give it a look.
I'm getting this warning when I run rspec:
/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:240:in `block in require': iconv will be deprecated in the future, use String#encode instead.
I get the same warning with rails 3.1.0, 3.1.1, 3.1.2.rc2 versions. Seems it's related to sqlite3 gem, but I'm not sure. There are no warnings with ruby 1.9.2
Any suggestions how to deal with it?
You are getting this deprecation notice cause a library somewhere is requiring iconv.
iconv is a gem created by Matz that can be used to convert strings from one format to another.
For example this is often used:
Iconv.iconv('UTF-8//IGNORE', 'UTF-8', content) this little bit of magic takes a UTF-8 string that may have invalid chars and converts it to a proper UTF-8 string.
It has been decided that in Ruby 1.9.3 we should not be using iconv any more and instead use the built-in String#encode. encode is more powerful and allows you more flexibility.
The theory is that the above example could be replaced with:
string.encode("UTF-8", :invalid => :replace, :undef => :replace, :replace => "?")
In practice it seems this is imperfect.
This also leads to a less than easy story for gem creators who wish to support 1.8:
content = RUBY_VERSION.to_f < 1.9 ?
Iconv.iconv('UTF-8//IGNORE', 'UTF-8', "content") :
"#{content}".encode(Encoding::UTF_8, :invalid => :replace, :undef => :replace, :replace => '')
So, you have a gem somewhere that is requiring iconv, to find it:
Assuming your error message is: /gems/activesupport-3.1.0/lib/active_support/dependencies.rb:240
Open up /gems/activesupport-3.1.0/lib/active_support/dependencies.rb on line 240:
Add the line:
p caller if file =~ /iconv/
(just after: load_dependency(file) { result = super })
You will get a big fat stack trace:
rake --tasks
/home/sam/.rvm/gems/ruby-1.9.3-p125/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:251:in `block in require': iconv will be deprecated in the future, use String#encode instead.
["/home/sam/.rvm/gems/ruby-1.9.3-p125/gems/calais-0.0.13/lib/calais.rb:5:in `'",
.. more omitted ..
This tells me it is the calais gem. Looking through pull requests, I am not the first. The pull has not been yanked in.
Depending on the gem, there may be an upgraded version that does not have this error, so I would recommend you upgrade your gems first. If you are unlucky you may be stuck with the unfortunate task of forking a gem to get rid of this (if for example your pull request to fix it languishes)
If you're seeing this, it's very probably not Rails. If you look at the method surrounding the line being referred to in the error you posted, you'll see the following:
def require(file, *)
result = false
load_dependency(file) { result = super }
result
end
I'm not saying it's your code, necessarily, but I'm certain that it's not actually the line in question where iconv is being called. In my case, I found that my project's code actually contained a reference to iconv.
If you want to check your code for such a reference, try grep -ir iconv ./ in your project directory.
When iconv is actually in a library it can be harder to find. By temporarily changing the above method to:
def require(file, *)
result = false
puts
puts caller.reverse
load_dependency(file) { result = super }
result
end
You can then easily run your code and grep out the relevant lines of the backtrace to find the root cause of the warning.
ruby your/code.rb 2>&1 | grep -B 5 iconv
Add this to the start of your program:
oldverb = $VERBOSE; $VERBOSE = nil
require 'iconv'
$VERBOSE = oldverb
and curse the people who think this is a professional way to handle deprecation.
You can pin down the exact location of the warning by generating exceptions for ActiveSupport::Deprecation, instead of just printing to the log. At the top of application.rb:
ActiveSupport::Deprecation.behavior = Proc.new do |message, backtrace|
raise message
end
Once you've figured out where the warning is coming from (by inspecting the full backtrace), remove this again.
To remove this warning...
go to your .rvm directory and find iconv.c (mine was at ~/.rvm/src/ruby-1.9.3-p125/ext/iconv/iconv.c)
edit that file are remove or comment out the call to warn_deprecated() (should be near the bottom)
from that file's directory, run ruby extconf.rb
then make
then make install
Should do the trick