Skip to content

Commit f3ff3f8

Browse files
Anita PatelAnita Patel
authored andcommitted
ruby script to convert png images to jpg
1 parent a630613 commit f3ff3f8

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

shell.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# array for base filenames
2+
base_names = []
3+
4+
# change into image directory
5+
Dir.chdir("image_batch")
6+
7+
# collect all base filenames
8+
Dir["*.png"].map{|file| base_names << file.split('.').first}
9+
10+
# using system call
11+
# 'magick' here is a version 7+ option, previous versions would be just 'convert'
12+
base_names.map {|file| system("magick convert #{file}.png #{file}.jpg")}
13+
14+
# option: using mini_magick
15+
#base_names.each do |file|
16+
#image = MiniMagick::Image.open("#{file}")
17+
#image.format "jpg"
18+
#image.write("#{file.split('.').first}.jpg")
19+
#end
20+
21+
# list all of the files in the image directory
22+
Dir["*"].map{|file| puts file}

0 commit comments

Comments
 (0)