{"record":{"id":"7a3b86d80c40e366","repo":"carrierwaveuploader/carrierwave","slug":"errors-messages-min-width-error","errorCode":null,"errorMessage":"errors.messages.min_width_error","messagePattern":"errors\\.messages\\.min_width_error","errorType":"exception","errorClass":"CarrierWave::IntegrityError","httpStatus":null,"severity":"error","filePath":"lib/carrierwave/uploader/dimension.rb","lineNumber":54,"sourceCode":"      #     def height_range\n      #       1000..\n      #     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":36,"sourceCodeEnd":67,"githubUrl":"https://github.com/carrierwaveuploader/carrierwave/blob/b5f0abe10ecf6500309fc83e0e8969cf57ba690e/lib/carrierwave/uploader/dimension.rb#L36-L67","documentation":"Raised as CarrierWave::IntegrityError when check_dimensions! sees an image narrower than the lower bound of the uploader's width_range (message errors.messages.min_width_error, with the bound formatted via number_to_delimited). The check only runs on the main version (version_name skipped), requires width/height support from CarrierWave::MiniMagick, RMagick, or Vips, and fires during caching before storage.","triggerScenarios":"Declaring width_range 800..1600 in an uploader (with an image module included) and uploading an image whose width is below 800 — e.g. a 400x300 avatar.","commonSituations":"Product requirements raise the minimum image size after launch and old clients still submit small ones; thumbnails/screenshots pasted at low resolution; cameras exporting smaller than expected; mobile crops producing narrow images.","solutions":["Lower or drop the minimum: width_range 100..1600 (or nil) to accept the real minimum","Validate dimensions client-side (or on upload forms) with the same bounds before submission","Rescue CarrierWave::IntegrityError and turn it into a model error with a helpful message","If small images should be upscaled instead of rejected, add a process step to resize to the minimum before validation"],"exampleFix":"# before\nclass AvatarUploader < CarrierWave::Uploader::Base\n  include CarrierWave::MiniMagick\n  width_range 800..1600 # 600px upload -> IntegrityError min_width_error\nend\n\n# after\nclass AvatarUploader < CarrierWave::Uploader::Base\n  include CarrierWave::MiniMagick\n  width_range 200..1600\nend","handlingStrategy":"validation","validationCode":"require 'fastimage'\n\nMIN_W = 800\nw, _h = FastImage.size(params[:image].path)\nreturn render_error(:too_narrow) if w && w < MIN_W\n# then assign to the uploader","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":["Mirror width_range bounds in client-side checks (read naturalWidth before submit) so users learn before the round-trip","Rescue CarrierWave::IntegrityError and present the i18n message with the formatted minimum","Revisit dimension ranges whenever input sources change (mobile crops, pasted screenshots)"],"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"}