Created
April 4, 2013 22:13
-
-
Save jl2/5314859 to your computer and use it in GitHub Desktop.
First attempt to automate creation of images like http://www.flickr.com/photos/rtadlock/8611207319/in/contacts/ In a Gist for now, will make a repo later tonight.
This file contains hidden or 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
| #include <iostream> | |
| #include <string> | |
| #include "Magick++.h" | |
| #include <boost/program_options.hpp> | |
| namespace po = boost::program_options; | |
| #include <vector> | |
| bool parseArgs(int argc, char *argv[], | |
| std::string &outputFile, std::vector<std::string> &inputFiles) { | |
| po::options_description desc("Allowed options"); | |
| desc.add_options() | |
| ("help", "print help message") | |
| ("output,o", po::value<std::string>(), "output file name") | |
| ("input,i", po::value< std::vector<std::string> >(), "input files"); | |
| po::positional_options_description p; | |
| p.add("input", -1); | |
| po::variables_map vm; | |
| po::store(po::command_line_parser(argc, argv).options(desc).positional(p).run(), vm); | |
| po::notify(vm); | |
| if (vm.count("help")) { | |
| std::cout << desc << "\n"; | |
| return false; | |
| } | |
| bool hasInput = false; | |
| bool hasOutput = false; | |
| if (vm.count("output")) { | |
| outputFile = vm["output"].as<std::string>(); | |
| hasOutput = true; | |
| } | |
| if (vm.count("input")) { | |
| inputFiles = vm["input"].as<std::vector<std::string>>(); | |
| hasInput = true; | |
| } | |
| if (!hasInput || !hasOutput) { | |
| std::cout << desc << "\n"; | |
| return false; | |
| } | |
| return true; | |
| } | |
| int main(int argc, char *argv[]) { | |
| Magick::InitializeMagick(*argv); | |
| std::string outputFileName; | |
| std::vector<std::string> inputFileNames; | |
| if (!parseArgs(argc, argv, outputFileName, inputFileNames)) { | |
| return 1; | |
| } | |
| Magick::Image base(inputFileNames[0]); | |
| for (size_t i = 1;i<inputFileNames.size(); ++i) { | |
| Magick::Image nextImage(inputFileNames[i]); | |
| Magick::Image tmp = base; | |
| tmp.composite(nextImage,0,0, Magick::CompositeOperator::DifferenceCompositeOp); | |
| base.composite(tmp,0,0,Magick::CompositeOperator::LightenCompositeOp); | |
| } | |
| base.write(outputFileName); | |
| return 0; | |
| } |
This file contains hidden or 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
| testing: testing.cpp Makefile | |
| g++ -std=c++11 -o testing testing.cpp -I/home/jl2/oss_code/-pthread `GraphicsMagick++-config --cppflags --cxxflags --ldflags --libs` -lboost_system -lboost_program_options |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment