app/models/post/file_methods.rb
# If the JPEG version needs to be generated (or regenerated), output it to tempfile_jpeg_path.  On
# error, return false; on success or no-op, return true.
If the JPEG version needs to be generated (or regenerated), output it to tempfile_jpeg_path.  On
error, return false; on success or no-op, return true.
If the JPEG version needs to be generated ( or regenerated ) output it to tempfile_jpeg_path . On error return false ; on success or no - op return true .
def generate_jpeg(force_regen = false)
    return true unless image?
    return true unless CONFIG["jpeg_enable"]
    return true unless width && height
    return true if (file_ext.downcase != "png")
    path = tempfile_path
    path = file_path unless File.exist?(path)
    unless File.exist?(path)
      errors.add(:file, "not found")
      throw :abort
    end
    if !force_regen && jpeg_width.is_a?(Integer)
      return true
    end
    size = Moebooru::Resizer.reduce_to({ :width => width, :height => height }, { :width => CONFIG["jpeg_width"], :height => CONFIG["jpeg_height"] }, CONFIG["jpeg_ratio"])
    begin
      Moebooru::Resizer.resize(file_ext, path, tempfile_jpeg_path, size, CONFIG["jpeg_quality"])
    rescue => x
      errors.add "jpeg", "couldn't be created: #{x}"
      throw :abort
    end
    self.jpeg_width = size[:width]
    self.jpeg_height = size[:height]
    self.jpeg_size = File.size(tempfile_jpeg_path)
    self.jpeg_crc32 = Moebooru::Hasher.compute_one(tempfile_jpeg_path, :crc32)
    true
  end
def generate_jpeg ( force_regen = false ) return true unless image? return true unless CONFIG [ "jpeg_enable" ] return true unless width && height return true if ( file_ext . downcase != "png" ) path = tempfile_path path = file_path unless File . exist? ( path ) unless File . exist? ( path ) errors . add ( :file , "not found" ) throw :abort end if ! force_regen && jpeg_width . is_a? ( Integer ) return true end size = Moebooru :: Resizer . reduce_to ( { :width => width , :height => height } , { :width => CONFIG [ "jpeg_width" ] , :height => CONFIG [ "jpeg_height" ] } , CONFIG [ "jpeg_ratio" ] ) begin Moebooru :: Resizer . resize ( file_ext , path , tempfile_jpeg_path , size , CONFIG [ "jpeg_quality" ] ) rescue => x errors . add "jpeg" , "couldn't be created: #{x}" throw :abort end self . jpeg_width = size [ :width ] self . jpeg_height = size [ :height ] self . jpeg_size = File . size ( tempfile_jpeg_path ) self . jpeg_crc32 = Moebooru :: Hasher . compute_one ( tempfile_jpeg_path , :crc32 ) true end
If the JPEG version needs to be generated (or regenerated), output it to tempfile_jpeg_path.
If the JPEG version needs to be generated ( or regenerated ) output it to tempfile_jpeg_path .
# Only generate JPEGs for PNGs.  Don't do it for files that are already JPEGs; we'll just add # artifacts and/or make the file bigger.  Don't do it for GIFs; they're usually animated. # We can generate the image during upload or offline.  Use tempfile_path # if it exists, otherwise use file_path. # If we already have the image, don't regenerate it.
force_regen