module

Tools::ImageHelper

Inherits Tools::FileHelper

Constants

ALLOWED_IMAGE_CONTENT_TYPES = ["image/png", "image/jpeg"]

Allowed image content types

ALLOWED_IMAGE_FORMATS = ["PNG", "JPEG"]

Allowed image formats

ALLOWED_IMAGE_MAGIC_B64 = ["iVBORw0KGgo", "/9j/"]

Base64-encoded magic bytes for allowed image formats, without padding so we can do prefix checking.

MAX_IMAGE_FILE_SIZE = (2 * 1024) * 1024
UNKNOWN_IMAGE_TYPE = "unknown"

Instance methods

allowed_image?(base64_encoded_string : String)
Source
determine_image_content_type(base64_encoded_string : String) : String

Determines the content type based on the magic bytes of the image

Source
load_image_file_as_data_url(resolved_path, max_image_file_size = MAX_IMAGE_FILE_SIZE) : String

Returns a data URL for the image in the file; assumes path is allowed; raises errors if unable to open file or if content is not an allowed image

Source