{"record":{"id":"98d2f989b3f831ce","repo":"carrierwaveuploader/carrierwave","slug":"errors-messages-max-width-error","errorCode":null,"errorMessage":"errors.messages.max_width_error","messagePattern":"errors\\.messages\\.max_width_error","errorType":"exception","errorClass":"CarrierWave::IntegrityError","httpStatus":null,"severity":"error","filePath":"lib/carrierwave/uploader/dimension.rb","lineNumber":56,"sourceCode":"      #     end\n      #\n      def height_range; end\n\n    private\n\n      def check_dimensions!(new_file)\n        # NOTE: Skip the check for resized images\n        return if version_name.present?\n        return unless width_range || height_range\n\n        unless respond_to?(:width) || respond_to?(:height)\n          raise 'You need to include one of CarrierWave::MiniMagick, CarrierWave::RMagick, or CarrierWave::Vips to perform image dimension validation'\n        end\n\n        if width_range&.begin && width < width_range.begin\n          raise CarrierWave::IntegrityError, I18n.translate(:\"errors.messages.min_width_error\", :min_width => ActiveSupport::NumberHelper.number_to_delimited(width_range.begin))\n        elsif width_range&.end && width > width_range.end\n          raise CarrierWave::IntegrityError, I18n.translate(:\"errors.messages.max_width_error\", :max_width => ActiveSupport::NumberHelper.number_to_delimited(width_range.end))\n        elsif height_range&.begin && height < height_range.begin\n          raise CarrierWave::IntegrityError, I18n.translate(:\"errors.messages.min_height_error\", :min_height => ActiveSupport::NumberHelper.number_to_delimited(height_range.begin))\n        elsif height_range&.end && height > height_range.end\n          raise CarrierWave::IntegrityError, I18n.translate(:\"errors.messages.max_height_error\", :max_height => ActiveSupport::NumberHelper.number_to_delimited(height_range.end))\n        end\n      end\n\n    end # Dimension\n  end # Uploader\nend # CarrierWave\n","sourceCodeStart":38,"sourceCodeEnd":67,"githubUrl":"https://github.com/carrierwaveuploader/carrierwave/blob/b5f0abe10ecf6500309fc83e0e8969cf57ba690e/lib/carrierwave/uploader/dimension.rb#L38-L67","documentation":"Raised as CarrierWave::IntegrityError when check_dimensions! sees an image wider than the upper bound of width_range (message errors.messages.max_width_error, bound formatted with thousands delimiters). It is checked only for the base version and only when the uploader has width/height methods from CarrierWave::MiniMagick, RMagick, or Vips; the elsif chain means width bounds are evaluated before height bounds.","triggerScenarios":"Declaring width_range 800..1600 and uploading a 3000px-wide panorama or full-resolution photo; large exports from design tools exceeding the configured maximum.","commonSituations":"Servers rejecting modern camera/phone photos (often 4000px+); width limits added to protect processing memory but users' originals exceed them; maximums tuned for one feature (avatars) accidentally applied to another uploader via copy-paste.","solutions":["Raise the upper bound to fit real inputs (width_range 100..5000), or set it explicitly per uploader","Downscale on upload instead of rejecting: process resize_to_limit: [1600, 1600] and relax the range (processing runs on versions, base check uses the original — consider resizing before validation or capping client-side)","Rescue CarrierWave::IntegrityError and surface a clear 'image too wide, max X px' message","Validate dimensions in the client/upload widget before the POST"],"exampleFix":"# before\nclass PhotoUploader < CarrierWave::Uploader::Base\n  include CarrierWave::MiniMagick\n  width_range 800..1600 # 4000px photo -> IntegrityError max_width_error\nend\n\n# after\nclass PhotoUploader < CarrierWave::Uploader::Base\n  include CarrierWave::MiniMagick\n  process resize_to_limit: [1600, nil]\n  width_range 100..4000\nend","handlingStrategy":"validation","validationCode":"require 'fastimage'\n\nMAX_W = 1600\nw, _h = FastImage.size(params[:image].path)\nreturn render_error(:too_wide) if w && w > MAX_W","typeGuard":"def within_width_range?(path, range)\n  w, = FastImage.size(path)\n  !w.nil? && (range.begin.nil? || w >= range.begin) && (range.end.nil? || w <= range.end)\nend","tryCatchPattern":"begin\n  record.save!\nrescue CarrierWave::IntegrityError => e\n  record.errors.add(:image, :dimensions_invalid, message: e.message)\n  render :new\nend","preventionTips":["Prefer downscaling over rejecting: process resize_to_limit plus a generous width_range","Reject oversized files client-side (naturalWidth check) before the upload starts to save bandwidth","Keep width caps per-uploader — don't copy avatar limits onto photo uploaders"],"tags":["carrierwave","image-dimensions","validation","upload","width"],"backgroundTag":"image-dimension-rejected","analyzedSha":"b5f0abe10ecf6500309fc83e0e8969cf57ba690e","analyzedAt":"2026-08-21T18:07:27.715Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}