# Converting gif images to png images on the fly for PDF generation

**URL:** <https://www.ruby-forum.com/t/converting-gif-images-to-png-images-on-the-fly-for-pdf-generation/175378>\
**Category:** Rails\
**Created:** [September 11, 2009, 11:10pm UTC](https://www.ruby-forum.com/t/converting-gif-images-to-png-images-on-the-fly-for-pdf-generation/175378 "2009-09-11T23:10:02Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hypnotizing\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/c37758/32.png) [@Hypnotizing\_C](https://www.ruby-forum.com/u/Hypnotizing_C)\
**Post date:** [September 11, 2009, 11:10pm UTC](https://www.ruby-forum.com/t/converting-gif-images-to-png-images-on-the-fly-for-pdf-generation/175378/1 "2009-09-11T23:10:02Z")

</div>

I have been using the prawn library + prawnto plugin to generate PDF  
files  
from a set of models. each model has one or more images associated with  
it  
and I include each of these images into the pdf by looping through the  
images collection associated with the model. (the images have been  
uploaded  
with paperclip.)  
Prawn does not support pdf generation from GIF - only jpg or png. is  
there a  
way for me to check if an image is a gif and convert it on the fly into  
a  
png image in my prawnto view?  
I guess converting the image into a png while uploading would also work  
but  
as I have a bunch of GIFs already uploaded, and Prawn throws up an  
“image  
file is an unrecognised format” when generating the PDF from those  
models, I  
would appreciate a solution where the image is converted into a png and  
included into the pdf.  
my prawn view: (there are a bunch of cards - each card has a message and  
0-n  
images)  
@deck.cards.each do |card|  
pdf.start\_new\_page  
pdf.text sanitize(card.message),:align =\> :center, :size =\> 30, :style  
=\>  
:bold  
card.images.each do |pic|

pdf.start\_new\_page  
picture = “#{RAILS\_ROOT}/public#{pic.data.url}”.sub!(/?.+\Z/, ‘’)  
pdf.image picture, :position =\> :center, :vposition =\> :center

end

end
