Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6541123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:03:56+00:00 2026-05-25T11:03:56+00:00

I’m trying to post watermarked images to a url using rmagick and rest-client. When

  • 0

I’m trying to post watermarked images to a url using rmagick and rest-client. When I generate the composite image, I save it (.write), read it back in with File.new, and then post that File object. Ideally though, I’d like to bypass the write operation because I’ll never need this photo again. Is there any way to convert a Magick::Image object into a File object so that I can post it with rest-client?

require 'rmagick'
require 'rest-client'

photo = Magick::Image.read('myphoto.jpg').first
water_mark = Magick::Image.read('watermark.png').first

result = photo.composite(water_mark, 0, 0, Magick::OverCompositeOp)
result.write('result.jpg')

file = File.new('result.jpg', 'rb')
RestClient.post("http://example.com", :source => file)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T11:03:57+00:00Added an answer on May 25, 2026 at 11:03 am

    I finally figured it out using StringIO and the Koala gem (ruby wrapper for the Facebook API). The code looks like this:

    access_token = "asdfasdfasdfasdf"
    graph = Koala::Facebook::API.new(access_token)
    photo = Magick::Image.read("my_photo.jpg").first
    watermark = Magick::Image.read("watermark.png").first
    watermarked = photo.composite(watermark, 5, 5, Magick::OverCompositeOp)
    photo_graph_id = StringIO.open(watermarked.to_blob) do |strio|
      response = graph.put_picture(strio, "image/jpeg", { "message" => "hi" })
      response['id']
    end
    

    The key was to call to_blob on the Magick::Image and then create a StringIO from that string. The current version of the Koala gem has a glitch with StringIO but I’ve fixed it in my fork and have submitted a pull request:

    https://github.com/arsduo/koala/pull/122

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I am trying to render a haml file in a javascript response like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.