### Install React Native Image Resizer (>= 0.61) Source: https://github.com/bamlab/react-native-image-resizer/blob/master/README.md Instructions for installing the React Native Image Resizer library for React Native versions 0.61 and above, including the command to add the package and link it for iOS. ```bash yarn add @bam.tech/react-native-image-resizer cd ios && pod install ``` -------------------------------- ### Resize Image with React Native Image Resizer Source: https://github.com/bamlab/react-native-image-resizer/blob/master/README.md Example of how to use the ImageResizer module to create a resized image. It demonstrates the function call, parameters, and the expected response object containing details of the new image. ```javascript import ImageResizer from '@bam.tech/react-native-image-resizer'; ImageResizer.createResizedImage( path, maxWidth, maxHeight, compressFormat, quality, rotation, outputPath ) .then((response) => { // response.uri is the URI of the new image that can now be displayed, uploaded... // response.path is the path of the new image // response.name is the name of the new image with the extension // response.size is the size of the new image }) .catch((err) => { // Oops, something went wrong. Check that the filename is correct and // inspect err to get more details. }); ``` -------------------------------- ### Install React Native Image Resizer (<= 0.60) Source: https://github.com/bamlab/react-native-image-resizer/blob/master/README.md Instructions for installing a specific version of the React Native Image Resizer library for React Native versions 0.60 and below, including the command to add the package and link it for iOS. ```bash yarn add react-native-image-resizer@1.1.0 cd ios && pod install ``` -------------------------------- ### Import ImageResizerPackage in MainApplication.java Source: https://github.com/bamlab/react-native-image-resizer/blob/master/docs/android_manual_config.md This Java code snippet illustrates the import statement required at the top of your MainApplication.java file. It makes the ImageResizerPackage class accessible for use in your React Native setup. ```java import com.reactnativeimageresizer.ImageResizerPackage; ``` -------------------------------- ### React Native: Image Format Conversion (JPEG, PNG, WEBP) Source: https://context7.com/bamlab/react-native-image-resizer/llms.txt Illustrates converting images between different formats like JPEG, PNG, and WEBP. This allows for optimizing file sizes and compatibility across platforms, with a note about WEBP's potential iOS limitations. ```javascript import ImageResizer from '@bam.tech/react-native-image-resizer'; // Convert PNG to JPEG with compression ImageResizer.createResizedImage( 'file:///transparent-image.png', 1024, 768, 'JPEG', 85, 0 ) .then((response) => { console.log('Converted to JPEG:', response.name); console.log('Original size vs new:', 'compare file sizes'); }); // Convert JPEG to PNG (lossless) ImageResizer.createResizedImage( 'file:///photo.jpg', 1024, 768, 'PNG', 100, 0 ) .then((response) => { console.log('Converted to PNG:', response.uri); }); // Convert to WEBP (Android only) ImageResizer.createResizedImage( 'file:///photo.jpg', 1024, 768, 'WEBP', 80, 0 ) .then((response) => { console.log('Converted to WEBP:', response.name); }) .catch((err) => { console.error('WEBP may not be supported on iOS:', err); }); ``` -------------------------------- ### Implement Module Dependency in app/build.gradle Source: https://github.com/bamlab/react-native-image-resizer/blob/master/docs/android_manual_config.md This code demonstrates how to add the react-native-image-resizer module as an implementation dependency in your app/build.gradle file. This makes the module's code available for use in your application. ```gradle dependencies { ... implementation project(':react-native-image-resizer') ... } ``` -------------------------------- ### React Native: Metadata Preservation during Resizing Source: https://context7.com/bamlab/react-native-image-resizer/llms.txt Demonstrates how to control EXIF and other metadata preservation during image resizing. The `keepMeta` parameter can be set to `true` to retain metadata, primarily for JPEG files from file system sources. ```javascript import ImageResizer from '@bam.tech/react-native-image-resizer'; // Preserve metadata (JPEG only, file system sources only) ImageResizer.createResizedImage( 'file:///photo-with-gps.jpg', 1200, 900, 'JPEG', 90, 0, null, true // keepMeta = true ) .then((response) => { console.log('Metadata preserved:', response.uri); // EXIF data including GPS, camera settings, etc. is preserved }); // Strip metadata (default behavior) ImageResizer.createResizedImage( 'file:///photo-with-gps.jpg', 1200, 900, 'JPEG', 90, 0, null, false // keepMeta = false (default) ) .then((response) => { console.log('Metadata removed:', response.uri); // All EXIF data is stripped from the output file }); ``` -------------------------------- ### Resize Modes Source: https://context7.com/bamlab/react-native-image-resizer/llms.txt Explains the different resize modes available for the `createResizedImage` function: 'contain', 'cover', and 'stretch'. ```APIDOC ## Resize Modes ### contain Fit the image within specified dimensions while preserving aspect ratio. #### Request Example ```javascript ImageResizer.createResizedImage( 'file:///photo.jpg', 800, 600, 'JPEG', 80, 0, null, false, { mode: 'contain' } ).then((response) => { console.log('Width:', response.width); // 800 console.log('Height:', response.height); // 600 }); ``` ### cover Ensure the image is at least as large as specified dimensions, cropping if necessary to maintain aspect ratio. #### Request Example ```javascript ImageResizer.createResizedImage( 'file:///landscape.jpg', 800, 800, 'JPEG', 80, 0, null, false, { mode: 'cover' } ).then((response) => { console.log('Dimensions:', response.width, 'x', response.height); }); ``` ### stretch Resize the image to exact dimensions, ignoring aspect ratio. #### Request Example ```javascript ImageResizer.createResizedImage( 'file:///photo.jpg', 800, 400, 'JPEG', 80, 0, null, false, { mode: 'stretch' } ).then((response) => { console.log('Width:', response.width); // 800 console.log('Height:', response.height); // 400 }); ``` ``` -------------------------------- ### Batch Image Processing with Progress Tracking in React Native Source: https://context7.com/bamlab/react-native-image-resizer/llms.txt Processes multiple images with specified resizing options and provides progress updates. It returns an object containing results, success count, failure count, and detailed error information. Dependencies include the '@bam.tech/react-native-image-resizer' package. ```javascript import ImageResizer from '@bam.tech/react-native-image-resizer'; const resizeBatch = async (imagePaths, options = {}) => { const { maxWidth = 1024, maxHeight = 1024, quality = 80, format = 'JPEG', onProgress = null } = options; const results = []; const errors = []; for (let i = 0; i < imagePaths.length; i++) { try { const resized = await ImageResizer.createResizedImage( imagePaths[i], maxWidth, maxHeight, format, quality, 0, null, false, { mode: 'contain', onlyScaleDown: true } ); results.push({ original: imagePaths[i], resized: resized, success: true }); if (onProgress) { onProgress(i + 1, imagePaths.length); } } catch (error) { errors.push({ path: imagePaths[i], error: error.message }); results.push({ original: imagePaths[i], resized: null, success: false, error: error.message }); } } return { results, successful: results.filter(r => r.success).length, failed: errors.length, errors }; }; // Usage const images = [ 'file:///path/to/image1.jpg', 'file:///path/to/image2.jpg', 'file:///path/to/image3.jpg' ]; resizeBatch(images, { maxWidth: 800, maxHeight: 600, quality: 85, onProgress: (current, total) => { console.log(`Processing ${current}/${total}`); } }) .then((result) => { console.log('Batch complete:'); console.log('Successful:', result.successful); console.log('Failed:', result.failed); if (result.errors.length > 0) { console.error('Errors:', result.errors); } }); ``` -------------------------------- ### Type-Safe Image Resizing with TypeScript in React Native Source: https://context7.com/bamlab/react-native-image-resizer/llms.txt Provides type-safe image resizing using TypeScript, defining interfaces for options and return types. This enhances code maintainability and reduces runtime errors by catching type mismatches during development. It requires the '@bam.tech/react-native-image-resizer' package with its TypeScript definitions. ```typescript import ImageResizer, { ResizeFormat, ResizeMode, Response } from '@bam.tech/react-native-image-resizer'; interface ResizeOptions { uri: string; width: number; height: number; format: ResizeFormat; quality: number; rotation?: number; outputPath?: string | null; keepMeta?: boolean; mode?: ResizeMode; onlyScaleDown?: boolean; } const resizeWithOptions = async ( options: ResizeOptions ): Promise => { const { uri, width, height, format, quality, rotation = 0, outputPath = null, keepMeta = false, mode = 'contain', onlyScaleDown = false } = options; try { const result: Response = await ImageResizer.createResizedImage( uri, width, height, format, quality, rotation, outputPath, keepMeta, { mode, onlyScaleDown } ); // Response object is fully typed console.log('Path:', result.path); // string console.log('URI:', result.uri); // string console.log('Size:', result.size); // number (bytes) console.log('Name:', result.name); // string console.log('Width:', result.width); // number (pixels) console.log('Height:', result.height); // number (pixels) return result; } catch (error) { console.error('Resize failed:', error); throw error; } }; // Usage with type safety resizeWithOptions({ uri: 'file:///photo.jpg', width: 1024, height: 768, format: 'JPEG', // Type: 'PNG' | 'JPEG' | 'WEBP' quality: 85, mode: 'contain', // Type: 'contain' | 'cover' | 'stretch' onlyScaleDown: true }); ``` -------------------------------- ### Register ImageResizerPackage in ReactInstanceManager Builder Source: https://github.com/bamlab/react-native-image-resizer/blob/master/docs/android_manual_config.md This Java code shows how to add the ImageResizerPackage to the ReactInstanceManager builder in your MainApplication.java file. This step is crucial for initializing the image resizer functionality within your React Native application. ```java ReactInstanceManager.Builder builder = ReactInstanceManager.builder() .setApplication(application) .setDefaultHardwareBackBtnHandler(application.getGAMActivity()) .setInitialLifecycleState(LifecycleState.RESUMED) .setCurrentActivity((Activity) application.getGAMActivity()) .addPackage(new RealmReactPackage()) .addPackage(new MainReactPackageWrapper()) .addPackage(new StoreReactNativePackage()) .addPackage(new ImageResizerPackage()) <------- (Add this package on the Builder list) .addPackage(gamCommunicationReactPackage); ``` -------------------------------- ### React Native: Specify Custom Output Path for Resized Images Source: https://context7.com/bamlab/react-native-image-resizer/llms.txt Shows how to provide a custom file path for saving resized images, overriding the default cache location. This requires the `react-native-fs` library for directory management. ```javascript import ImageResizer from '@bam.tech/react-native-image-resizer'; import RNFS from 'react-native-fs'; // Save to custom directory const outputPath = `${RNFS.DocumentDirectoryPath}/resized-images/photo-${Date.now()}.jpg`; ImageResizer.createResizedImage( 'file:///photo.jpg', 800, 600, 'JPEG', 80, 0, outputPath ) .then((response) => { console.log('Saved to:', response.path); console.log('Full URI:', response.uri); }); // Default behavior (null outputPath) - saves to cache ImageResizer.createResizedImage( 'file:///photo.jpg', 800, 600, 'JPEG', 80, 0, null // Will save to cache directory ) .then((response) => { console.log('Saved to cache:', response.path); }); ``` -------------------------------- ### Process Remote Image URL using JavaScript Source: https://context7.com/bamlab/react-native-image-resizer/llms.txt Downloads an image from a given HTTP URL and resizes it using react-native-image-resizer. It logs the original URL and the details of the downloaded and resized image, including its local path. Requires `@bam.tech/react-native-image-resizer`. ```javascript import ImageResizer from '@bam.tech/react-native-image-resizer'; const processRemoteImage = async (imageUrl) => { try { console.log('Processing URL:', imageUrl); const resized = await ImageResizer.createResizedImage( imageUrl, 800, 600, 'JPEG', 75, 0, null, false, { mode: 'contain', onlyScaleDown: true } ); console.log('Downloaded and resized:', resized.uri); console.log('Local path:', resized.path); console.log('File size:', resized.size, 'bytes'); console.log('Dimensions:', resized.width, 'x', resized.height); return resized; } catch (error) { console.error('Failed to process remote image:', error); throw error; } }; // Usage const imageUrl = 'https://example.com/large-image.jpg'; processRemoteImage(imageUrl) .then((local) => { console.log('Image cached locally:', local.path); }) .catch((err) => { console.error('Download failed:', err.message); }); ``` -------------------------------- ### Add Module to settings.gradle Source: https://github.com/bamlab/react-native-image-resizer/blob/master/docs/android_manual_config.md This snippet shows how to manually include the react-native-image-resizer module in your Android project's settings.gradle file. This step is necessary when you choose not to use 'react-native link' for dependency management. ```gradle include ':react-native-image-resizer' project(':react-native-image-resizer').projectDir = new File(rootProject.projectDir, '../node_modules/@bam.tech/react-native-image-resizer/android') ``` -------------------------------- ### Image Resizing API Source: https://github.com/bamlab/react-native-image-resizer/blob/master/README.md The `createResizedImage` function allows you to resize and compress images within your React Native application. It supports various input formats and provides options for quality, format, and output path. ```APIDOC ## POST /createResizedImage ### Description Resizes and compresses an image to specified dimensions and format. Supports various input URIs including local paths, base64 strings, and HTTP links. ### Method POST ### Endpoint /createResizedImage ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **uri** (string) - Required - The URI of the image file. Accepts a local path, a base64 encoded string (prefixed with 'data:image/imagetype'), or an HTTP link. - **maxWidth** (number) - Required - The maximum width for the resized image. - **maxHeight** (number) - Required - The maximum height for the resized image. - **compressFormat** (string) - Required - The compression format. Can be 'JPEG', 'PNG', or 'WEBP' (Android only). - **quality** (number) - Required - The quality of the compression, a number between 0 and 100. Used for JPEG compression. - **rotation** (number) - Optional - Rotation to apply to the image in degrees (0 by default). For iOS, rotation is rounded to multiples of 90 degrees. - **outputPath** (string) - Optional - The desired path for the resized image. If null, the image is stored in the cache directory. - **keepMeta** (boolean) - Optional - If true, attempts to preserve image metadata (defaults to false). Only applicable for JPEG images loaded from the file system. - **options** (object) - Optional - Additional options for resizing. ### Request Example ```json { "uri": "file:///path/to/your/image.jpg", "maxWidth": 100, "maxHeight": 100, "compressFormat": "JPEG", "quality": 80, "rotation": 0, "outputPath": "file:///path/to/save/resized.jpg", "keepMeta": false, "options": {} } ``` ### Response #### Success Response (200) - **path** (string) - The local file path of the resized image. - **uri** (string) - The URI of the resized image, usable as a React Native Image source. - **name** (string) - The filename of the resized image. - **size** (number) - The size of the resized image in bytes. - **width** (number) - The width of the resized image in pixels. - **height** (number) - The height of the resized image in pixels. #### Response Example ```json { "path": "file:///path/to/cache/resized_image.jpg", "uri": "file:///path/to/cache/resized_image.jpg", "name": "resized_image.jpg", "size": 15000, "width": 100, "height": 100 } ``` ``` -------------------------------- ### createResizedImage Function Source: https://context7.com/bamlab/react-native-image-resizer/llms.txt Resizes, compresses, and optionally rotates an image with configurable quality, format, and output path. Supports various resize modes and options. ```APIDOC ## createResizedImage ### Description Resizes, compresses, and optionally rotates an image with configurable quality, format, and output path. Supports various resize modes and options. ### Method `createResizedImage` ### Parameters - **uri** (string) - Required - The local file path or URI of the image to resize. - **maxWidth** (number) - Required - The maximum width the resized image should have. - **maxHeight** (number) - Required - The maximum height the resized image should have. - **format** (string) - Required - The desired output image format (e.g., 'JPEG', 'PNG'). - **quality** (number) - Required - The compression quality for JPEG images (0-100). - **rotation** (number) - Optional - The degree to rotate the image (0, 90, 180, 270). - **outputPath** (string) - Optional - A custom path for the resized image file. - **keepMeta** (boolean) - Optional - Whether to preserve image metadata. - **options** (object) - Optional - Configuration object for resize mode and other behaviors. - **mode** (string) - 'contain', 'cover', or 'stretch'. - **onlyScaleDown** (boolean) - If true, the image will only be scaled down, not up. ### Request Example ```javascript import ImageResizer from '@bam.tech/react-native-image-resizer'; ImageResizer.createResizedImage( 'file:///path/to/image.jpg', 800, 600, 'JPEG', 80, 0, null, false, { mode: 'contain', onlyScaleDown: false } ) .then((response) => { console.log(response.uri); }) .catch((err) => { console.error(err.message); }); ``` ### Response #### Success Response (Promise resolves with an object) - **uri** (string) - The URI of the resized image. - **path** (string) - The file path of the resized image. - **name** (string) - The filename of the resized image. - **size** (number) - The size of the resized image in bytes. - **width** (number) - The width of the resized image. - **height** (number) - The height of the resized image. #### Response Example ```json { "uri": "file:///path/to/resized/image.jpg", "path": "/path/to/resized/image.jpg", "name": "resized_image.jpg", "size": 150000, "width": 800, "height": 600 } ``` #### Error Response (Promise rejects with an error object) - **message** (string) - Description of the error. #### Error Example ```json { "message": "Failed to resize image." } ``` ``` -------------------------------- ### Resize Photo Captured with Camera using JavaScript Source: https://context7.com/bamlab/react-native-image-resizer/llms.txt Captures a photo using react-native-vision-camera and then resizes it with react-native-image-resizer. It includes platform-specific path handling for Android and logs captured and resized photo details. Requires `react-native-vision-camera` and `@bam.tech/react-native-image-resizer`. ```javascript import ImageResizer from '@bam.tech/react-native-image-resizer'; import { Camera } from 'react-native-vision-camera'; import { Platform } from 'react-native'; const captureAndResize = async (camera) => { try { const photo = await camera.current.takePhoto({ qualityPrioritization: 'quality' }); // Platform-specific path handling const photoPath = Platform.OS === 'android' ? `file://${photo.path}` : photo.path; console.log('Photo captured:', photoPath); const resized = await ImageResizer.createResizedImage( photoPath, 1920, 1080, 'JPEG', 85, 0, null, false, { mode: 'cover', onlyScaleDown: true } ); console.log('Resized photo:', resized.uri); console.log('Dimensions:', resized.width, 'x', resized.height); console.log('File size:', (resized.size / 1024).toFixed(2), 'KB'); return resized; } catch (error) { console.error('Error capturing/resizing:', error); throw error; } }; // Usage example const MyCameraComponent = () => { const cameraRef = useRef(null); const handleCapture = async () => { const resized = await captureAndResize(cameraRef); console.log('Ready for upload:', resized.path); }; return ; }; ``` -------------------------------- ### Resize Image from Device Gallery using JavaScript Source: https://context7.com/bamlab/react-native-image-resizer/llms.txt Resizes an image selected from the device gallery using react-native-image-picker and react-native-image-resizer. It handles user cancellation and logs original and resized image details. Requires `react-native-image-picker` and `@bam.tech/react-native-image-resizer`. ```javascript import ImageResizer from '@bam.tech/react-native-image-resizer'; import { launchImageLibrary } from 'react-native-image-picker'; const selectAndResizeImage = async () => { try { const result = await launchImageLibrary({ mediaType: 'photo', quality: 1 }); if (result.didCancel || !result.assets || !result.assets[0]) { console.log('User cancelled image picker'); return; } const asset = result.assets[0]; console.log('Original image:', asset.uri); console.log('Original size:', asset.fileSize, 'bytes'); const resized = await ImageResizer.createResizedImage( asset.uri, 1024, 1024, 'JPEG', 80, 0, null, false, { mode: 'contain', onlyScaleDown: true } ); console.log('Resized image:', resized.uri); console.log('New size:', resized.size, 'bytes'); console.log('Compression ratio:', ((1 - resized.size / asset.fileSize) * 100).toFixed(1) + '%'); return resized; } catch (error) { console.error('Error processing image:', error); throw error; } }; // Usage selectAndResizeImage() .then((resized) => { console.log('Ready to upload:', resized.path); }); ``` -------------------------------- ### Fix Android Gradle Build Error Source: https://github.com/bamlab/react-native-image-resizer/blob/master/README.md A common solution for Android build errors related to multiple dex files in React Native projects using this library. It involves cleaning the Android build. ```bash cd android && ./gradlew clean ``` -------------------------------- ### Resize Image using createResizedImage (JavaScript) Source: https://github.com/bamlab/react-native-image-resizer/blob/master/README.md The `createResizedImage` function resizes an image to specified dimensions, allowing for format conversion, quality adjustment, rotation, and output path control. It accepts various URI types and returns a Promise that resolves with details of the resized image. Ensure correct input types and handle the promise resolution for the output. ```javascript createResizedImage( uri, maxWidth, maxHeight, compressFormat, quality, (rotation = 0), outputPath, (keepMeta = false), (options = {}) ); // The promise resolves with an object containing: path, uri, name, size (bytes), width (pixels), and height of the new file. ``` -------------------------------- ### Resize Image with 'cover' Mode in React Native Source: https://context7.com/bamlab/react-native-image-resizer/llms.txt This function resizes an image to ensure it covers the specified target dimensions, cropping if necessary to maintain the original aspect ratio. This mode guarantees that the output image will fill the target area, making it ideal for scenarios like generating thumbnails that must occupy a specific space without distortion. ```javascript import ImageResizer from '@bam.tech/react-native-image-resizer'; // Image: 1600x900, Target: 800x800 // Result: 800x800 (one dimension matches, aspect ratio preserved) ImageResizer.createResizedImage( 'file:///landscape.jpg', 800, 800, 'JPEG', 80, 0, null, false, { mode: 'cover' } ) .then((response) => { console.log('Dimensions:', response.width, 'x', response.height); // Output: "Dimensions: 800 x 800" }); // Useful for thumbnails that must fill a square container ImageResizer.createResizedImage( 'file:///profile-photo.jpg', 200, 200, 'JPEG', 90, 0, null, false, { mode: 'cover' } ) .then((response) => { console.log('Thumbnail created:', response.uri); }); ``` -------------------------------- ### React Native: Image Rotation during Resize Source: https://context7.com/bamlab/react-native-image-resizer/llms.txt Shows how to rotate an image by a specified degree (0, 90, 180, 270) as part of the resizing process. This is useful for correcting image orientation or applying creative effects. ```javascript import ImageResizer from '@bam.tech/react-native-image-resizer'; // Rotate 90 degrees clockwise ImageResizer.createResizedImage( 'file:///photo.jpg', 800, 600, 'JPEG', 80, 90 ) .then((response) => { console.log('Rotated image:', response.uri); }); // Rotate 180 degrees ImageResizer.createResizedImage( 'file:///photo.jpg', 800, 600, 'JPEG', 80, 180 ) .then((response) => { console.log('Upside down image:', response.uri); }); // Rotate 270 degrees (or -90 degrees) ImageResizer.createResizedImage( 'file:///photo.jpg', 800, 600, 'JPEG', 80, 270 ) .then((response) => { console.log('Rotated counter-clockwise:', response.uri); }); ``` -------------------------------- ### React Native: Scale Image Down Only Source: https://context7.com/bamlab/react-native-image-resizer/llms.txt Demonstrates how to use the `onlyScaleDown` option to prevent images from being enlarged beyond their original dimensions. This is useful for ensuring performance and maintaining image quality by only resizing larger images to fit target dimensions. ```javascript import ImageResizer from '@bam.tech/react-native-image-resizer'; // Image: 640x480, Target: 1920x1080 // With onlyScaleDown: true, result: 640x480 (unchanged) ImageResizer.createResizedImage( 'file:///small-image.jpg', 1920, 1080, 'JPEG', 80, 0, null, false, { mode: 'contain', onlyScaleDown: true } ) .then((response) => { console.log('Dimensions:', response.width, 'x', response.height); // Output: "Dimensions: 640 x 480" }); // Image: 2400x1800, Target: 1920x1080 // With onlyScaleDown: true, result: 1440x1080 (scaled down) ImageResizer.createResizedImage( 'file:///large-image.jpg', 1920, 1080, 'JPEG', 80, 0, null, false, { mode: 'contain', onlyScaleDown: true } ) .then((response) => { console.log('Dimensions:', response.width, 'x', response.height); // Output: "Dimensions: 1440 x 1080" }); ``` -------------------------------- ### Resize Image with 'stretch' Mode in React Native Source: https://context7.com/bamlab/react-native-image-resizer/llms.txt This function resizes an image to exact target dimensions, ignoring its original aspect ratio. The image will be stretched or compressed to fit the specified width and height precisely. This mode can lead to distortion if the aspect ratios of the source image and the target dimensions do not match. ```javascript import ImageResizer from '@bam.tech/react-native-image-resizer'; // Image: 1600x1200 (4:3), Target: 800x400 (2:1) // Result: 800x400 (stretched to exact dimensions) ImageResizer.createResizedImage( 'file:///photo.jpg', 800, 400, 'JPEG', 80, 0, null, false, { mode: 'stretch' } ) .then((response) => { console.log('Width:', response.width); // 800 console.log('Height:', response.height); // 400 // Note: Image may appear distorted if aspect ratios don't match }); ``` -------------------------------- ### Resize Image with 'contain' Mode in React Native Source: https://context7.com/bamlab/react-native-image-resizer/llms.txt This function resizes an image to fit within specified target dimensions while maintaining its original aspect ratio. If the image's aspect ratio does not match the target dimensions, it will be scaled down proportionally to fit entirely within the bounds. This mode is useful for ensuring an image is fully visible without distortion. ```javascript import ImageResizer from '@bam.tech/react-native-image-resizer'; // Image: 1600x1200, Target: 800x600 // Result: 800x600 (scaled down proportionally) ImageResizer.createResizedImage( 'file:///photo.jpg', 800, 600, 'JPEG', 80, 0, null, false, { mode: 'contain' } ) .then((response) => { console.log('Width:', response.width); // 800 console.log('Height:', response.height); // 600 }); // Image: 1600x900 (16:9), Target: 800x800 // Result: 800x450 (maintains 16:9 ratio, fits within bounds) ImageResizer.createResizedImage( 'file:///wide-photo.jpg', 800, 800, 'JPEG', 80, 0, null, false, { mode: 'contain' } ) .then((response) => { console.log('Width:', response.width); // 800 console.log('Height:', response.height); // 450 }); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.