<commit_before>class BarcodesController < ApplicationController
  def index
  end

  def show
    base_width = 100
    if params[:id]
      pdf_width = base_width + (params[:id].length * 14)
    end
    @barcode_data = params[:id]
    temp_data = @barcode_data
    respond_to do |format|
      format.html {}
      format.pdf { prawnto :prawn=>{page_size: [pdf_width || 200,40], margin: [1,1,1,1]} }
      format.jpg {
        template = File.read("#{Rails.root}/app/views/barcodes/show.pdf.prawn")
            pdf = Prawn::Document.new(page_size: [pdf_width || 200,40], margin: [1,1,1,1])
            pdf.instance_eval do
              @barcode_data = temp_data
              eval(template) #this evaluates the template with your variables
            end
            the_file = pdf.render
        file_name = "#{Rails.root}/tmp/#{params[:id]}.pdf"
        File.open(file_name, 'w:ASCII-8BIT') do |f|
          f.write the_file
        end
        require 'RMagick'
        im = Magick::Image.read(file_name)
        im[0].write(file_name + ".jpg"){ self.quality = 95 }
        send_data File.read("#{file_name}.jpg"), :type => 'image/jpeg', :disposition => 'inline'
      }
    end

  end
end<commit_msg>improving jpg quality more<commit_after>class BarcodesController < ApplicationController
  def index
  end

  def show
    base_width = 100
    if params[:id]
      pdf_width = base_width + (params[:id].length * 14)
    end
    @barcode_data = params[:id]
    temp_data = @barcode_data
    respond_to do |format|
      format.html {}
      format.pdf { prawnto :prawn=>{page_size: [pdf_width || 200,40], margin: [1,1,1,1]} }
      format.jpg {
        template = File.read("#{Rails.root}/app/views/barcodes/show.pdf.prawn")
            pdf = Prawn::Document.new(page_size: [pdf_width || 200,40], margin: [1,1,1,1])
            pdf.instance_eval do
              @barcode_data = temp_data
              eval(template) #this evaluates the template with your variables
            end
            the_file = pdf.render
        file_name = "#{Rails.root}/tmp/#{params[:id]}.pdf"
        File.open(file_name, 'w:ASCII-8BIT') do |f|
          f.write the_file
        end
        require 'RMagick'
        im = Magick::Image.read(file_name)
        final = im[0].resize_to_fill(pdf_width, 40)
        im[0].write(file_name + ".jpg"){ self.quality = 95 }
        send_data File.read("#{file_name}.jpg"), :type => 'image/jpeg', :disposition => 'inline'
      }
    end

  end
end
{'fraction_non_alphanumeric': 0.13685910375454177, 'fraction_numerical': 0.023011707710940653, 'mean_word_length': 2.4273858921161824, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6329570', 'n_tokens_mistral': 863, 'n_tokens_neox': 823, 'n_words': 169}