Convert Text to Image File JPEG, PNG or GIF in Ruby

Convert Text to Image File JPEG, PNG or GIF in Ruby

TXT file is a simple text document format that supports plain text. You can convert your TXT files to JPG, PNG, GIF formats quickly using GroupDocs API. It is secure & easy to use method to convert your Text to image file format in seconds. In this article, we will learn how to convert Text to Image File JPEG, PNG or GIF in Ruby.

The following topics shall be covered in this article:

Text to Images Conversion REST API - Installation

To convert Text to picture JPEG, PNG or GIF in Ruby, we will be using the Ruby SDK of GroupDocs.Conversion Cloud API. GroupDocs.Conversion API provides the best way to convert Text(.txt) to JPG, PNG and GIF files in seconds. It is 100% free, secure and easy to use Ruby SDK for files conversion. It allows converting documents of supported formats to image programmatically on the cloud. You can install it using the following command in the console:

gem install groupdocs_conversion_cloud

Firstly, get your Client ID and Secret from the dashboard before following the below mentioned steps. Once you have your ID and secret, add below code in your application as shown below:

Convert Text to JPG/JPEG file format using REST API

You can convert text file to images by following the simple steps given below: Firstly, you need to upload of the dashboard on the cloud. Now, let’s learn steps for how to convert text to jpg file programmatically as given below:

  • Firstly, create an instance of the ConvertApi
  • Next, create an instance of the ConvertSettings
  • Set the storage name and input text file path
  • Also, assign “jpeg” or “jpg” as output image format
  • Create an instance of the TxtLoadOptions
  • Set the text file shift_jis and assign load_options
  • Create an instance of the JpegConvertOptions or JpgConvertOptions
  • Define the grayscale, from_page, pages_count, quality, rotate_angle and use_pdf values
  • Set convertOptions to settings
  • Now, provide the output file path
  • After that, create ConvertDocumentRequest with ConvertSettings as argument
  • Finally, call the ConvertApi.convert_document() method with ConvertDocumentRequest to save the converted file.

The following code sample shows how to convert Text document to JPEG image using REST API in Ruby:

The above code sample will save the converted JPEG file on the cloud. You can also download it by adding the download file API.

Convert Text to PNG format using REST API in Ruby

You can convert Text to PNG format programmatically by following the steps given below:

  • Create an instance of the ConvertApi
  • Next, create an instance of the ConvertSettings
  • Set the storage name and input text file path
  • Provide “png” as output image format
  • Create an instance of the TxtLoadOptions
  • Set the text file shift_jis and assign load_options
  • Create an instance of the PngConvertOptions
  • Define the grayscale, from_page, pages_count, quality, rotate_angle and use_pdf values
  • Set convertOptions to settings
  • Now, provide the output file path
  • After that, create ConvertDocumentRequest with ConvertSettings as argument
  • Finally, call the ConvertApi.convert_document() method with ConvertDocumentRequest to save the converted file

The following code example shows how to convert text to photo PNG format in Ruby using REST API:

How to Convert Text to GIF file format in Ruby API

You can convert Text to GIF programmatically by following the steps given below:

  • Create an instance of the ConvertApi
  • Next, create an instance of the ConvertSettings
  • Then, set the text file path with storage name
  • Set “gif” as output image format
  • Create an instance of the TxtLoadOptions
  • Set the text file shift_jis and assign load_options
  • Create an instance of the GifConvertOptions
  • Define the grayscale, from_page, pages_count, quality, rotate_angle and use_pdf etc.
  • Set convertOptions to settings
  • Now, provide the output file path
  • After that, create ConvertDocumentRequest with ConvertSettings as argument
  • Finally, call the ConvertApi.convert_document() method with ConvertDocumentRequest to save the converted file.

The following code sample shows how to convert Text to GIF file using REST API in Ruby:

Free Online Text to Image Converter

Please try the following free online JPG, PNG and GIF conversion tool, which is developed using the above API.

Conclusion

In this article, we have learned how to convert text to picture formats on the cloud. Now you know:

  • how to convert text document to jpeg/jpg format using ruby;
  • how to convert text to png image format in ruby;
  • how to convert text to gif file format using ruby API;

You can learn more about GroupDocs.Conversion Cloud API using the documentation. We also provide an API Reference section that lets you visualize and interact with our APIs directly through the browser.

Ask a question

If you have any questions about text to image converter, please feel free to ask us on the Support Forum.

See Also