Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8839103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:09:55+00:00 2026-06-14T10:09:55+00:00

I am pulling my hair out and have been searching for a solution for

  • 0

I am pulling my hair out and have been searching for a solution for days. I am trying to take an uploaded pdf document and create a thumbnail that is viewable on all browsers. I can get it to work on Safari/iOS or Firefox/IE7+/Chrome but not one version that works everywhere. I’ve tried setting the colorspace to rgb(no effect), converting to png instead of jpg(no effect) and setting :set_content_type(no effect). I am getting the same result on my local machine and on production(Heroku).

pdfdoc_uploader.rb

include ImageManipulators
include CarrierWave::RMagick
include CarrierWave::MimeTypes

version :thumb do

 process :convert => 'jpg'  #<---This works in Safari and iOS
 process :resize_to_fit => [200, 200]
 process :paper_shape
 process :strip
 process :convert => 'jpg'  #<---Move it here and it works everywhere else

 def full_filename (for_file = model.logo.file)
   super.chomp(File.extname(super)) + '.jpg'
 end     
end

image_manipulators.rb

module ImageManipulators

# creates an image with a 3x4 aspect ratio
def paper_shape
  manipulate! do |img|
if img.rows*4 != img.columns*3
  width=img.columns
  height=img.columns/3*4
  img.crop!(0,0,width,height,true)
else
  img
end
  end
 end

def set_content_type(*args)
   self.file.instance_variable_set(:@content_type, "image/jpeg")
end

# Autoorients image according to exif
 def auto_orient
   manipulate! {|img| img.auto_orient! || img }
 end

 # Crops the biggest possible square from the image
 def biggest_square
   manipulate! do |img|
     if img.rows != img.columns
       max = img.rows > img.columns ? img.columns : img.rows
       img.crop!(0,0,max,max,true)
     else
       img
     end
   end
 end

def paper_shape
  manipulate! do |img|
     if img.rows*4 != img.columns*3
       width=img.columns
       height=img.columns/3*4
       img.crop!(0,0,width,height,true)
     else
       img
     end
  end
 end

 # Create rounded corners for the image
 def rounded_corners
   radius = 10
   manipulate! do |img|
     #create a masq of same size
     masq = Magick::Image.new(img.columns, img.rows)
     d = Magick::Draw.new
     d.roundrectangle(0, 0, img.columns - 1, img.rows - 1, radius, radius)
     d.draw(masq)
     img.composite(masq, 0, 0, Magick::LightenCompositeOp)
   end
 end

 # Rotates the image based on the EXIF Orientation
     def fix_exif_rotation
       manipulate! do |img|
         img.auto_orient!
         img = yield(img) if block_given?
         img
       end
     end

     # Strips out all embedded information from the image
     def strip
       manipulate! do |img|
         img.strip!
         img = yield(img) if block_given?
         img
       end
     end

     def colorspace(cs)
         manipulate! do |img|
           case cs
           when 'rgb'
             img.colorspace = Magick::RGBColorspace
           when 'cmyk'
             img.colorspace = Magick::CMYKColorspace
           end
           img = yield(img) if block_given?
           img
         end
       end
end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T10:09:56+00:00Added an answer on June 14, 2026 at 10:09 am

    I eventually gave up and just created two versions and used useragent to determine which one to display. While not an attractive option it is working. I hope someone comes up with a better solution.

    version :thumb_safari do #special version for safari and ios
      process :resize_to_fit => [200,200]
      process :convert => 'jpg'
      process :paper_shape
      def full_filename (for_file = model.logo.file)
         super.chomp(File.extname(super)) + '.jpg'
      end     
    end
    
    version :thumb do #all browsers except safari
      process :resize_to_fit => [200,200]
      process :convert => 'jpg' #must convert to jpg before running paper shape
      process :paper_shape
      process :convert => 'jpg' #after running paper_shape it will default to original file type
      def full_filename (for_file = model.logo.file)
        super.chomp(File.extname(super)) + '.jpg'
      end
    end
    
    def paper_shape
       manipulate! do |img|
         if img.rows*4 != img.columns*3
           width=img.columns
           height=img.columns/3*4
           img.crop!(0,0,width,height,true)
         else
           img
         end
       end
     end
    

    In the controller/view I used the useragent gem and did this:

    documents_controller.rb

    def index
      @user_agent=UserAgent.parse(request.user_agent)
      @search = Document.search(params[:q])
    end
    

    index.html.rb

    <% if @user_agent.browser.downcase == 'safari' %>
    <%= link_to(image_tag(doc.pdfdoc_url(:thumb_safari).to_s, :class=>"dropshadow", :size => "150x225"), doc.pdfdoc_url)%>
    <% else %>
    <%= link_to(image_tag(doc.pdfdoc_url(:thumb).to_s, :class=>"dropshadow", :size => "150x225"), doc.pdfdoc_url)%>
    <% end %>
    

    No doubt there is a better way to do this but this is working for now.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been pulling my hair out trying to figure out what I can't
I have been pulling my hair out trying to make this work. I have
I have been pulling my hair trying to figure this out but nothing is
I've been pulling out my hair trying to figure this problem out. I have
I have been pulling my hair out over the past few days with a
Have been pulling out my hair trying to find out why my sessions are
I have been pulling my hair out trying to solve this. What I am
I have been pulling my hair out trying to get the shadows to work
I've dug through all the tutorials and have been pulling my hair out trying
I have been pulling out my hair trying to figure out why this is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.