Skip to content

Instantly share code, notes, and snippets.

@groupdocs-cloud-gists
Last active July 23, 2022 08:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save groupdocs-cloud-gists/20fd59d0f6259170c684aa48cf12335e to your computer and use it in GitHub Desktop.
Save groupdocs-cloud-gists/20fd59d0f6259170c684aa48cf12335e to your computer and use it in GitHub Desktop.
Convert Text to Image File JPEG, PNG or GIF in Ruby
# How to convert Text to GIF image format
# Getting instance of the Convert API
@apiInstance = GroupDocsConversionCloud::ConvertApi.from_keys(@app_sid, @app_key)
# Initialize convert settings
@settings = GroupDocsConversionCloud::ConvertSettings.new()
@settings.storage_name = @storage_name
@settings.file_path = "text-to-image/sample-file.txt"
@settings.format = "gif"
# Text load options
@loadOptions = GroupDocsConversionCloud::TxtLoadOptions()
@loadOptions.encoding = "shift_jis"
@settings.load_options = @loadOptions
@convertOptions = GroupDocsConversionCloud::GifConvertOptions.new()
@convertOptions.grayscale = true
@convertOptions.from_page = 1
@convertOptions.pages_count = 1
@convertOptions.quality = 100
@convertOptions.rotate_angle = 90
@convertOptions.use_pdf = false
@settings.convert_options = @convertOptions
@settings.output_path = "text-to-image"
@request = GroupDocsConversionCloud::ConvertDocumentRequest.new(@settings)
@result = @apiInstance.convert_document(@request)
puts("Successfully converted Text to gif image format.")

You can convert Text to image file formats programmatically on the cloud. In this article, you will learn how to convert text file to image format using REST API in Ruby.

The following topics are covered in this article:

  1. Text to Images Conversion REST API – Installation
  2. Convert Text to JPG/JPEG file format using REST API
  3. Convert Text to PNG format using REST API in Ruby
  4. How to Convert Text to GIF file format in Ruby API
# How to convert Text to JPG/JPEG file format
# Getting instance of the ConvertAPI
@apiInstance = GroupDocsConversionCloud::ConvertApi.from_keys(@app_sid, @app_key)
# Initialize and set convert settings
@settings = GroupDocsConversionCloud::ConvertSettings.new()
@settings.storage_name = @storage_name
@settings.file_path = "text-to-image/sample-file.txt"
@settings.format = "jpeg"
# Text load options
@loadOptions = GroupDocsConversionCloud::TxtLoadOptions()
@loadOptions.encoding = "shift_jis"
@settings.load_options = @loadOptions
@convertOptions = GroupDocsConversionCloud::JpegConvertOptions.new()
@convertOptions.grayscale = true
@convertOptions.from_page = 1
@convertOptions.pages_count = 1
@convertOptions.quality = 100
@convertOptions.rotate_angle = 90
@convertOptions.use_pdf = false
@settings.convert_options = @convertOptions
@settings.output_path = "text-to-image"
@request = GroupDocsConversionCloud::ConvertDocumentRequest.new(@settings)
@result = @apiInstance.convert_document(@request)
puts("Text successfully converted to jpeg format. " + (@result).to_s)
# How to convert Text to PNG format
# Getting instance of the Convert API
@apiInstance = GroupDocsConversionCloud::ConvertApi.from_keys(@app_sid, @app_key)
# Initialize convert settings
@settings = GroupDocsConversionCloud::ConvertSettings.new()
@settings.storage_name = @storage_name
@settings.file_path = "text-to-image/sample-file.txt"
@settings.format = "png"
# Text load options
@loadOptions = GroupDocsConversionCloud::TxtLoadOptions()
@loadOptions.encoding = "shift_jis"
@settings.load_options = @loadOptions
@convertOptions = GroupDocsConversionCloud::PngConvertOptions.new()
@convertOptions.grayscale = true
@convertOptions.from_page = 1
@convertOptions.pages_count = 1
@convertOptions.quality = 100
@convertOptions.rotate_angle = 90
@convertOptions.use_pdf = false
@settings.convert_options = @convertOptions
@settings.output_path = "text-to-image"
@request = GroupDocsConversionCloud::ConvertDocumentRequest.new(@settings)
@result = @apiInstance.convert_document(@request)
puts("Text .txt file converted to png file image. ")
# Load Text file to Image Conversion REST API in your rails application:
require 'groupdocs_conversion_cloud'
# Get your client_id and client_secret from https://dashboard.groupdocs.cloud after free registration.
@app_sid = "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
@app_key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
@storage_name = "DefaultStorage"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment