Image to Image in Ruby

This page describes how to use our cloud-based API to convert between images formats in Ruby. The API is user-friendly and can be integrated into your application with just a few lines of code.

Installation

The Ruby API client library provides easy access to the Pdfcrowd API. No third-party libraries are required.

Install the client library from rubygems.org
gem install pdfcrowd

We also offer other installation options.

Authentication

The credentials to access the API are your Pdfcrowd username and the API key.

API Method Reference

Refer to the Image to Image Ruby Reference for a description of all API methods.

Code Examples

Here are a few Ruby examples to get you started quickly with the API. See more examples.

require "pdfcrowd"

begin
    # create the API client instance
    client = Pdfcrowd::ImageToImageClient.new("your_username", "your_apikey")

    # configure the conversion
    client.setOutputFormat("jpg")

    # run the conversion and write the result to a file
    client.convertFileToFile("/path/to/logo.png", "logo.jpg")
rescue Pdfcrowd::Error => why
    # report the error
    STDERR.puts "Pdfcrowd Error: #{why}"

    # rethrow or handle the exception
    raise
end
require "pdfcrowd"

begin
    # create the API client instance
    client = Pdfcrowd::ImageToImageClient.new("your_username", "your_apikey")

    # configure the conversion
    client.setOutputFormat("jpg")

    # run the conversion and write the result to a file
    client.convertUrlToFile("https://pdfcrowd.com/static/images/logo.png", "logo.jpg")
rescue Pdfcrowd::Error => why
    # report the error
    STDERR.puts "Pdfcrowd Error: #{why}"

    # rethrow or handle the exception
    raise
end
require "pdfcrowd"

begin
    # create the API client instance
    client = Pdfcrowd::ImageToImageClient.new("your_username", "your_apikey")

    # configure the conversion
    client.setOutputFormat("jpg")

    # run the conversion and write the result to a file
    client.convertRawDataToFile(open('/path/to/logo.png', 'rb').read(), "logo.jpg")
rescue Pdfcrowd::Error => why
    # report the error
    STDERR.puts "Pdfcrowd Error: #{why}"

    # rethrow or handle the exception
    raise
end

Troubleshooting