examples/identify.rb in rmagick-2.16.0 vs examples/identify.rb in rmagick-3.0.0
- old
+ new
@@ -29,157 +29,146 @@
puts "\t\tOpacity: #{channel_depth(Magick::OpacityChannel)}-bits\n" if matte
when Magick::GrayColorspace
puts "\t\tGray: #{channel_depth(Magick::GrayChannel)}-bits\n"
puts "\t\tOpacity: #{channel_depth(Magick::OpacityChannel)}-bits\n" if matte
end
- scale = Magick::QuantumRange / (Magick::QuantumRange >> (Magick::MAGICKCORE_QUANTUM_DEPTH-channel_depth))
+ scale = Magick::QuantumRange / (Magick::QuantumRange >> (Magick::MAGICKCORE_QUANTUM_DEPTH - channel_depth))
puts "\tChannel statistics:\n"
case color_space
when Magick::RGBColorspace
puts "\t\tRed:\n"
- puts "\t\t\tMin: " + sprintf("%u (%g)\n", channel_extrema(Magick::RedChannel)[0]/scale, channel_extrema(Magick::RedChannel)[0]/Magick::QuantumRange)
- puts "\t\t\tMax: " + sprintf("%u (%g)\n", channel_extrema(Magick::RedChannel)[1]/scale, channel_extrema(Magick::RedChannel)[1]/Magick::QuantumRange)
- puts "\t\t\tMean: " + sprintf("%g (%g)\n", channel_mean(Magick::RedChannel)[0]/scale, channel_mean(Magick::RedChannel)[0]/Magick::QuantumRange)
- puts "\t\t\tStandard deviation: " + sprintf("%g (%g)\n", channel_mean(Magick::RedChannel)[1]/scale, channel_mean(Magick::RedChannel)[1]/Magick::QuantumRange)
+ puts "\t\t\tMin: " + format("%u (%g)\n", channel_extrema(Magick::RedChannel)[0] / scale, channel_extrema(Magick::RedChannel)[0] / Magick::QuantumRange)
+ puts "\t\t\tMax: " + format("%u (%g)\n", channel_extrema(Magick::RedChannel)[1] / scale, channel_extrema(Magick::RedChannel)[1] / Magick::QuantumRange)
+ puts "\t\t\tMean: " + format("%g (%g)\n", channel_mean(Magick::RedChannel)[0] / scale, channel_mean(Magick::RedChannel)[0] / Magick::QuantumRange)
+ puts "\t\t\tStandard deviation: " + format("%g (%g)\n", channel_mean(Magick::RedChannel)[1] / scale, channel_mean(Magick::RedChannel)[1] / Magick::QuantumRange)
puts "\t\tGreen:\n"
- puts "\t\t\tMin: " + sprintf("%u (%g)\n", channel_extrema(Magick::GreenChannel)[0]/scale, channel_extrema(Magick::GreenChannel)[0]/Magick::QuantumRange)
- puts "\t\t\tMax: " + sprintf("%u (%g)\n", channel_extrema(Magick::GreenChannel)[1]/scale, channel_extrema(Magick::GreenChannel)[1]/Magick::QuantumRange)
- puts "\t\t\tMean: " + sprintf("%g (%g)\n", channel_mean(Magick::GreenChannel)[0]/scale, channel_mean(Magick::GreenChannel)[0]/Magick::QuantumRange)
- puts "\t\t\tStandard deviation: " + sprintf("%g (%g)\n", channel_mean(Magick::GreenChannel)[1]/scale, channel_mean(Magick::GreenChannel)[1]/Magick::QuantumRange)
+ puts "\t\t\tMin: " + format("%u (%g)\n", channel_extrema(Magick::GreenChannel)[0] / scale, channel_extrema(Magick::GreenChannel)[0] / Magick::QuantumRange)
+ puts "\t\t\tMax: " + format("%u (%g)\n", channel_extrema(Magick::GreenChannel)[1] / scale, channel_extrema(Magick::GreenChannel)[1] / Magick::QuantumRange)
+ puts "\t\t\tMean: " + format("%g (%g)\n", channel_mean(Magick::GreenChannel)[0] / scale, channel_mean(Magick::GreenChannel)[0] / Magick::QuantumRange)
+ puts "\t\t\tStandard deviation: " + format("%g (%g)\n", channel_mean(Magick::GreenChannel)[1] / scale, channel_mean(Magick::GreenChannel)[1] / Magick::QuantumRange)
puts "\t\tBlue:\n"
- puts "\t\t\tMin: " + sprintf("%u (%g)\n", channel_extrema(Magick::BlueChannel)[0]/scale, channel_extrema(Magick::BlueChannel)[0]/Magick::QuantumRange)
- puts "\t\t\tMax: " + sprintf("%u (%g)\n", channel_extrema(Magick::BlueChannel)[1]/scale, channel_extrema(Magick::BlueChannel)[1]/Magick::QuantumRange)
- puts "\t\t\tMean: " + sprintf("%g (%g)\n", channel_mean(Magick::BlueChannel)[0]/scale, channel_mean(Magick::BlueChannel)[0]/Magick::QuantumRange)
- puts "\t\t\tStandard deviation: " + sprintf("%g (%g)\n", channel_mean(Magick::BlueChannel)[1]/scale, channel_mean(Magick::BlueChannel)[1]/Magick::QuantumRange)
+ puts "\t\t\tMin: " + format("%u (%g)\n", channel_extrema(Magick::BlueChannel)[0] / scale, channel_extrema(Magick::BlueChannel)[0] / Magick::QuantumRange)
+ puts "\t\t\tMax: " + format("%u (%g)\n", channel_extrema(Magick::BlueChannel)[1] / scale, channel_extrema(Magick::BlueChannel)[1] / Magick::QuantumRange)
+ puts "\t\t\tMean: " + format("%g (%g)\n", channel_mean(Magick::BlueChannel)[0] / scale, channel_mean(Magick::BlueChannel)[0] / Magick::QuantumRange)
+ puts "\t\t\tStandard deviation: " + format("%g (%g)\n", channel_mean(Magick::BlueChannel)[1] / scale, channel_mean(Magick::BlueChannel)[1] / Magick::QuantumRange)
when Magick::CMYKColorspace
puts "\t\tCyan:\n"
- puts "\t\t\tMin: " + sprintf("%u (%g)\n", channel_extrema(Magick::CyanChannel)[0]/scale, channel_extrema(Magick::CyanChannel)[0]/Magick::QuantumRange)
- puts "\t\t\tMax: " + sprintf("%u (%g)\n", channel_extrema(Magick::CyanChannel)[1]/scale, channel_extrema(Magick::CyanChannel)[1]/Magick::QuantumRange)
- puts "\t\t\tMean: " + sprintf("%g (%g)\n", channel_mean(Magick::CyanChannel)[0]/scale, channel_mean(Magick::CyanChannel)[0]/Magick::QuantumRange)
- puts "\t\t\tStandard deviation: " + sprintf("%g (%g)\n", channel_mean(Magick::CyanChannel)[1]/scale, channel_mean(Magick::CyanChannel)[1]/Magick::QuantumRange)
+ puts "\t\t\tMin: " + format("%u (%g)\n", channel_extrema(Magick::CyanChannel)[0] / scale, channel_extrema(Magick::CyanChannel)[0] / Magick::QuantumRange)
+ puts "\t\t\tMax: " + format("%u (%g)\n", channel_extrema(Magick::CyanChannel)[1] / scale, channel_extrema(Magick::CyanChannel)[1] / Magick::QuantumRange)
+ puts "\t\t\tMean: " + format("%g (%g)\n", channel_mean(Magick::CyanChannel)[0] / scale, channel_mean(Magick::CyanChannel)[0] / Magick::QuantumRange)
+ puts "\t\t\tStandard deviation: " + format("%g (%g)\n", channel_mean(Magick::CyanChannel)[1] / scale, channel_mean(Magick::CyanChannel)[1] / Magick::QuantumRange)
puts "\t\tMagenta:\n"
- puts "\t\t\tMin: " + sprintf("%u (%g)\n", channel_extrema(Magick::MagentaChannel)[0]/scale, channel_extrema(Magick::MagentaChannel)[0]/Magick::QuantumRange)
- puts "\t\t\tMax: " + sprintf("%u (%g)\n", channel_extrema(Magick::MagentaChannel)[1]/scale, channel_extrema(Magick::MagentaChannel)[1]/Magick::QuantumRange)
- puts "\t\t\tMean: " + sprintf("%g (%g)\n", channel_mean(Magick::MagentaChannel)[0]/scale, channel_mean(Magick::MagentaChannel)[0]/Magick::QuantumRange)
- puts "\t\t\tStandard deviation: " + sprintf("%g (%g)\n", channel_mean(Magick::MagentaChannel)[1]/scale, channel_mean(Magick::MagentaChannel)[1]/Magick::QuantumRange)
+ puts "\t\t\tMin: " + format("%u (%g)\n", channel_extrema(Magick::MagentaChannel)[0] / scale, channel_extrema(Magick::MagentaChannel)[0] / Magick::QuantumRange)
+ puts "\t\t\tMax: " + format("%u (%g)\n", channel_extrema(Magick::MagentaChannel)[1] / scale, channel_extrema(Magick::MagentaChannel)[1] / Magick::QuantumRange)
+ puts "\t\t\tMean: " + format("%g (%g)\n", channel_mean(Magick::MagentaChannel)[0] / scale, channel_mean(Magick::MagentaChannel)[0] / Magick::QuantumRange)
+ puts "\t\t\tStandard deviation: " + format("%g (%g)\n", channel_mean(Magick::MagentaChannel)[1] / scale, channel_mean(Magick::MagentaChannel)[1] / Magick::QuantumRange)
puts "\t\tYellow:\n"
- puts "\t\t\tMin: " + sprintf("%u (%g)\n", channel_extrema(Magick::YellowChannel)[0]/scale, channel_extrema(Magick::YellowChannel)[0]/Magick::QuantumRange)
- puts "\t\t\tMax: " + sprintf("%u (%g)\n", channel_extrema(Magick::YellowChannel)[1]/scale, channel_extrema(Magick::YellowChannel)[1]/Magick::QuantumRange)
- puts "\t\t\tMean: " + sprintf("%g (%g)\n", channel_mean(Magick::YellowChannel)[0]/scale, channel_mean(Magick::YellowChannel)[0]/Magick::QuantumRange)
- puts "\t\t\tStandard deviation: " + sprintf("%g (%g)\n", channel_mean(Magick::YellowChannel)[1]/scale, channel_mean(Magick::YellowChannel)[1]/Magick::QuantumRange)
+ puts "\t\t\tMin: " + format("%u (%g)\n", channel_extrema(Magick::YellowChannel)[0] / scale, channel_extrema(Magick::YellowChannel)[0] / Magick::QuantumRange)
+ puts "\t\t\tMax: " + format("%u (%g)\n", channel_extrema(Magick::YellowChannel)[1] / scale, channel_extrema(Magick::YellowChannel)[1] / Magick::QuantumRange)
+ puts "\t\t\tMean: " + format("%g (%g)\n", channel_mean(Magick::YellowChannel)[0] / scale, channel_mean(Magick::YellowChannel)[0] / Magick::QuantumRange)
+ puts "\t\t\tStandard deviation: " + format("%g (%g)\n", channel_mean(Magick::YellowChannel)[1] / scale, channel_mean(Magick::YellowChannel)[1] / Magick::QuantumRange)
puts "\t\tBlack:\n"
- puts "\t\t\tMin: " + sprintf("%u (%g)\n", channel_extrema(Magick::BlackChannel)[0]/scale, channel_extrema(Magick::BlackChannel)[0]/Magick::QuantumRange)
- puts "\t\t\tMax: " + sprintf("%u (%g)\n", channel_extrema(Magick::BlackChannel)[1]/scale, channel_extrema(Magick::BlackChannel)[1]/Magick::QuantumRange)
- puts "\t\t\tMean: " + sprintf("%g (%g)\n", channel_mean(Magick::BlackChannel)[0]/scale, channel_mean(Magick::BlackChannel)[0]/Magick::QuantumRange)
- puts "\t\t\tStandard deviation: " + sprintf("%g (%g)\n", channel_mean(Magick::BlackChannel)[1]/scale, channel_mean(Magick::BlackChannel)[1]/Magick::QuantumRange)
+ puts "\t\t\tMin: " + format("%u (%g)\n", channel_extrema(Magick::BlackChannel)[0] / scale, channel_extrema(Magick::BlackChannel)[0] / Magick::QuantumRange)
+ puts "\t\t\tMax: " + format("%u (%g)\n", channel_extrema(Magick::BlackChannel)[1] / scale, channel_extrema(Magick::BlackChannel)[1] / Magick::QuantumRange)
+ puts "\t\t\tMean: " + format("%g (%g)\n", channel_mean(Magick::BlackChannel)[0] / scale, channel_mean(Magick::BlackChannel)[0] / Magick::QuantumRange)
+ puts "\t\t\tStandard deviation: " + format("%g (%g)\n", channel_mean(Magick::BlackChannel)[1] / scale, channel_mean(Magick::BlackChannel)[1] / Magick::QuantumRange)
when Magick::GrayColorspace
puts "\t\tGray:\n"
- puts "\t\t\tMin: " + sprintf("%u (%g)\n", channel_extrema(Magick::GrayChannel)[0]/scale, channel_extrema(Magick::GrayChannel)[0]/Magick::QuantumRange)
- puts "\t\t\tMax: " + sprintf("%u (%g)\n", channel_extrema(Magick::GrayChannel)[1]/scale, channel_extrema(Magick::GrayChannel)[1]/Magick::QuantumRange)
- puts "\t\t\tMean: " + sprintf("%g (%g)\n", channel_mean(Magick::GrayChannel)[0]/scale, channel_mean(Magick::GrayChannel)[0]/Magick::QuantumRange)
- puts "\t\t\tStandard deviation: " + sprintf("%g (%g)\n", channel_mean(Magick::GrayChannel)[1]/scale, channel_mean(Magick::GrayChannel)[1]/Magick::QuantumRange)
+ puts "\t\t\tMin: " + format("%u (%g)\n", channel_extrema(Magick::GrayChannel)[0] / scale, channel_extrema(Magick::GrayChannel)[0] / Magick::QuantumRange)
+ puts "\t\t\tMax: " + format("%u (%g)\n", channel_extrema(Magick::GrayChannel)[1] / scale, channel_extrema(Magick::GrayChannel)[1] / Magick::QuantumRange)
+ puts "\t\t\tMean: " + format("%g (%g)\n", channel_mean(Magick::GrayChannel)[0] / scale, channel_mean(Magick::GrayChannel)[0] / Magick::QuantumRange)
+ puts "\t\t\tStandard deviation: " + format("%g (%g)\n", channel_mean(Magick::GrayChannel)[1] / scale, channel_mean(Magick::GrayChannel)[1] / Magick::QuantumRange)
end
if matte
puts "\t\tOpacity:\n"
- puts "\t\t\tMin: " + sprintf("%u (%g)\n", channel_extrema(Magick::OpacityChannel)[0]/scale, channel_extrema(Magick::OpacityChannel)[0]/Magick::QuantumRange)
- puts "\t\t\tMax: " + sprintf("%u (%g)\n", channel_extrema(Magick::OpacityChannel)[1]/scale, channel_extrema(Magick::OpacityChannel)[1]/Magick::QuantumRange)
- puts "\t\t\tMean:" + sprintf("%u (%g)\n", channel_mean(Magick::OpacityChannel)[0]/scale, channel_mean(Magick::OpacityChannel)[0]/Magick::QuantumRange)
- puts "\t\t\tStandard deviation:" + sprintf("%u (%g)\n", channel_mean(Magick::OpacityChannel)[1]/scale, channel_mean(Magick::OpacityChannel)[1]/Magick::QuantumRange)
+ puts "\t\t\tMin: " + format("%u (%g)\n", channel_extrema(Magick::OpacityChannel)[0] / scale, channel_extrema(Magick::OpacityChannel)[0] / Magick::QuantumRange)
+ puts "\t\t\tMax: " + format("%u (%g)\n", channel_extrema(Magick::OpacityChannel)[1] / scale, channel_extrema(Magick::OpacityChannel)[1] / Magick::QuantumRange)
+ puts "\t\t\tMean:" + format("%u (%g)\n", channel_mean(Magick::OpacityChannel)[0] / scale, channel_mean(Magick::OpacityChannel)[0] / Magick::QuantumRange)
+ puts "\t\t\tStandard deviation:" + format("%u (%g)\n", channel_mean(Magick::OpacityChannel)[1] / scale, channel_mean(Magick::OpacityChannel)[1] / Magick::QuantumRange)
end
if class_type == Magick::DirectClass
puts "\tColors: #{total_colors}\n"
+ elsif total_colors <= colors
+ puts "\tColors: #{colors}\n"
else
- if total_colors <= colors
- puts "\tColors: #{colors}\n"
- else
- puts "\tColors: #{total_colors}=>#{colors}\n"
- end
+ puts "\tColors: #{total_colors}=>#{colors}\n"
end
# Histogram goes here
puts "\tMean error per pixel: #{mean_error_per_pixel}\n" if mean_error_per_pixel != 0.0
puts "\tNormalized mean error: #{normalized_mean_error}\n" if normalized_mean_error != 0.0
puts "\tNormalized maximum error: #{normalized_maximum_error}\n" if normalized_maximum_error != 0.0
puts "\tRendering-intent: #{rendering_intent}\n"
puts "\tGamma: #{gamma}\n" if gamma != 0.0
chrom = chromaticity
if chrom.red_primary.x != 0.0 || chrom.green_primary.x != 0.0 || chrom.blue_primary.x != 0.0 || chrom.white_point.x != 0.0
puts "\tChromaticity:\n"
- puts "\t\tred primary: (#{sprintf('%g,%g', chrom.red_primary.x, chrom.red_primary.y)})\n"
- puts "\t\tgreen primary: (#{sprintf('%g,%g', chrom.green_primary.x, chrom.green_primary.y)})\n"
- puts "\t\tblue primary: (#{sprintf('%g,%g', chrom.blue_primary.x, chrom.blue_primary.y)})\n"
- puts "\t\twhite point: (#{sprintf('%g,%g', chrom.white_point.x, chrom.white_point.y)})\n"
+ puts "\t\tred primary: (#{format('%g,%g', chrom.red_primary.x, chrom.red_primary.y)})\n"
+ puts "\t\tgreen primary: (#{format('%g,%g', chrom.green_primary.x, chrom.green_primary.y)})\n"
+ puts "\t\tblue primary: (#{format('%g,%g', chrom.blue_primary.x, chrom.blue_primary.y)})\n"
+ puts "\t\twhite point: (#{format('%g,%g', chrom.white_point.x, chrom.white_point.y)})\n"
end
ex_info = extract_info
- if ex_info.width * ex_info.height != 0.0
- puts "\tTile geometry: #{ex_info.width}x#{ex_info.height}+#{ex_info.x}+#{ex_info.y}\n"
- end
- if x_resolution != 0.0 && y_resolution != 0.0
- puts "\tResolution: #{sprintf('%gx%g', x_resolution, y_resolution)}\n"
- end
+ puts "\tTile geometry: #{ex_info.width}x#{ex_info.height}+#{ex_info.x}+#{ex_info.y}\n" if ex_info.width * ex_info.height != 0.0
+ puts "\tResolution: #{format('%gx%g', x_resolution, y_resolution)}\n" if x_resolution != 0.0 && y_resolution != 0.0
puts "\tUnits: #{units}\n"
size = filesize
- if size >= 1048576
- puts "\tFilesize: #{'%.1f' % (size/1048576.0)}mb\n"
+ if size >= 1_048_576
+ puts "\tFilesize: #{format('%.1f', (size / 1_048_576.0))}mb\n"
elsif size >= 1024
- puts "\tFilesize: #{'%.0f' % (size/1024.0)}kb\n"
+ puts "\tFilesize: #{format('%.0f', (size / 1024.0))}kb\n"
else
puts "\tFilesize: #{size}b\n"
end
puts "\tInterlace: #{interlace}\n"
puts "\tBackground Color: #{background_color}\n"
puts "\tBorder Color: #{border_color}\n"
puts "\tMatte Color: #{matte_color}\n"
pg = page
- if pg.width != 0 || pg.height != 0 || pg.x != 0 || pg.y != 0
- puts "\tPage geometry: #{pg.width}x#{pg.height}+#{pg.x}+#{pg.y}\n"
- end
+ puts "\tPage geometry: #{pg.width}x#{pg.height}+#{pg.x}+#{pg.y}\n" if pg.width != 0 || pg.height != 0 || pg.x != 0 || pg.y != 0
puts "\tDispose: #{dispose}\n"
puts "\tDelay: #{delay}\n" if delay != 0
puts "\tIterations: #{iterations}\n" unless iterations == 1
puts "\tScene: #{scene}\n" if scene != 0
puts "\tCompression: #{compression}\n"
- puts "\tQuality: #{quality}\n" unless quality == 0
+ puts "\tQuality: #{quality}\n" unless quality.zero?
puts "\tOrientation: #{orientation}\n"
puts "\tMontage: #{montage}\n" if montage
signature # compute but ignore - will be displayed along with the other properties
properties.each do |prop, value|
- next if prop[0,1] == '['
+ next if prop[0, 1] == '['
+
puts "\t#{prop}: #{value}\n"
end
clip_path = self['8BIM:1999,2998:#1']
- if clip_path
- puts "\tClipping path: #{clip_path}\n"
- end
+ puts "\tClipping path: #{clip_path}\n" if clip_path
each_profile do |name, value|
puts "\tProfile-#{name}: #{value.length}\n"
- if name == 'exif'
- exif_attrs = get_exif_by_entry
- exif_attrs.each do |attr|
- puts "\t\t#{attr[0]}: #{attr[1]}\n"
- end
+ next unless name == 'exif'
+
+ exif_attrs = get_exif_by_entry
+ exif_attrs.each do |attr|
+ puts "\t\t#{attr[0]}: #{attr[1]}\n"
end
end
puts "\tTainted: True\n" if changed?
puts "\tTainted: False\n" unless changed?
puts "\tVersion: #{Magick::Version}\n"
puts "\t #{Magick::Magick_version}\n"
end
end
end
-if ARGV.length == 0
+if ARGV.length.zero?
puts <<-'END_USAGE'
This example displays information about the specified image file(s)
that is similar to ImageMagick/GraphicsMagick's identify command.
Usage:
ruby identify.rb filename [filename...]
- END_USAGE
+ END_USAGE
exit
end
ilist = Magick::ImageList.new(*ARGV)
-ilist.each do |img|
- img.identify
-end
+ilist.each(&:identify)
exit