Brijesh
Brijesh

Reputation: 27

Why won't this code allow me to hide a pdf file "inside" of a png file using Ruby?

I'm trying to hide a file called "hello_world.pdf" inside of an image file "kitten.png". The code I'm using is:

original_image_file = File.read("kitten.png")
hidden_file = File.read("hello_world.pdf")
output_file = "output.png"

separator = "*----------[#{hidden_file}]----------*"
output = [original_image_file, separator, hidden_file]

File.open(output_file,'wb') do |f_out|
    output.each do |f|
        f_out.puts f
    end
end

I'm supposed to be able to click on output.png and see the original image (kitten.png), but then if I change the file extension to .pdf and click on output.pdf, it's supposed to show me hello_world.pdf.

However, when I click on output.png or output.pdf, in both cases it says it can't display the image or pdf. Do you have any idea why this is not working correctly?

Upvotes: 1

Views: 107

Answers (1)

K J
K J

Reputation: 11847

You don't need a separator. Simply add 2 files back to back, in different ways, MAY work in different viewers, but not all. So here the cat is a PDF in Firefox or a PNG in MS Edge but no assurances they can work in Acrobat as it is not an ISO PDF format.

enter image description here

enter image description here

Some viewers may see one as both !

enter image description here

Others may explain why.

enter image description here

So overall the one that is fooled easiest is a web browser such as Firefox and PDFjs, as it's an image viewer that also converts PDF into images:

enter image description here

Upvotes: 0

Related Questions