Created
August 31, 2020 07:15
-
-
Save emad-elsaid/2f179013f597777c74c4fd37fda05b70 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# frozen_string_literal: true | |
require 'bundler/inline' | |
require 'fileutils' | |
gemfile do | |
source 'https://rubygems.org' | |
gem 'gtk3' | |
end | |
source = File.expand_path '~/source/of/all/images' | |
destination = File.expand_path '~/path/to/blog/images/directory' | |
dialog = Gtk::FileChooserDialog.new( | |
title: 'Pick an image', | |
action: :open, | |
buttons: [ | |
[Gtk::Stock::CANCEL, :cancel], | |
[Gtk::Stock::OPEN, :accept] | |
] | |
) | |
dialog.set_current_folder(source) | |
if dialog.run == :accept | |
sourcefile = dialog.filename | |
filename = File.basename(sourcefile) | |
destinationfile = File.join(destination, filename) | |
FileUtils.cp(sourcefile, destinationfile) | |
relativefile = File.join('/path/prefix/for/markdown/', filename) | |
markdown = "![#{filename}](#{relativefile})" | |
`mogrify -strip #{destinationfile}` # remove EXIF data | |
IO.popen('xsel -i -b', 'w') { |f| f << markdown } | |
end | |
dialog.destroy |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment