-
Notifications
You must be signed in to change notification settings - Fork 9
/
image-artifact
executable file
·41 lines (32 loc) · 995 Bytes
/
image-artifact
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env ruby
# frozen_string_literal: true
# image-artifact.rb
# Author: William Woodruff
# ------------------------
# Exacerbate artifacts in an image by converting it to a JPEG and
# reading/writing it multiple times at low qualities. The final result is
# saved as "artifact.jpg".
# ------------------------
# This code is licensed by William Woodruff under the MIT License.
# http://opensource.org/licenses/MIT
require "rmagick"
def usage
puts "Usage: #{$PROGRAM_NAME} <image> <count>"
puts "\t<image> - the image to operate on"
puts "\t<count> - the number of times to cycle open/write on the file (1+)"
exit 1
end
usage if ARGV.size < 2
file, count = ARGV.shift 2
count = count.to_i
usage if !File.file?(file) || (count <= 0)
img = Magick::Image.read(file).first
img.write("artifact.jpg") do
self.quality = rand 1..75
end
(count - 1).times do
img = Magick::Image.read("artifact.jpg").first
img.write("artifact.jpg") do
self.quality = rand 1..75
end
end