New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

react-native-media-size

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-media-size

Get image size correctly

latest
Source
npmnpm
Version
0.2.0
Version published
Maintainers
1
Created
Source

📸 react-native-media-size

A simple React Native native module for retrieving accurate image dimensions (width & height) from content:// URIs on Android devices using the MediaSize API.

✅ Android only
❌ Not compatible with iOS

🚀 Features

  • 🔍 Retrieve image size from Android MediaSize
  • ⚡ Works with content:// URIs (e.g. selected images from gallery)
  • 📦 Lightweight and easy to use
  • 🔧 Written in Kotlin + TypeScript
  • 💬 Fully typed API

📦 Installation

Using npm:

npm install react-native-media-size
yarn add react-native-media-size

Usage

import { getImageSize } from 'react-native-media-size';

type ImageSize = {
  width: number;
  height: number;
};

const uri = 'content://media/external/images/media/123';

try {
  const size = await getImageSize(uri);
  console.log('Image size:', size.width, size.height);
} catch (error) {
  console.error('Failed to get image size:', error);
}

Example Utility Wrapper

utils/getImageRealSize
import { getImageSize } from 'react-native-media-size';

export const fetchImageSize = async (imageUri: string) => {
  try {
    const size = await getImageSize(imageUri);
    return size;
  } 
  catch (err) {
    console.error('Cannot get image size:', err);
  }
};

Platform Check Usage

const [selectedPhoto, setSelectedPhoto] = useState<string | undefined>(undefined);

import { fetchImageSize } from '../../utils/getRealImageSize';

if (Platform.OS === 'android' && selectedPhoto.startsWith('content://')) {
    const realSize = await fetchImageSize(selectedPhoto);
    if (realSize) {
      originalWidth = realSize.width;
      originalHeight = realSize.height;
    } 
    else {
      console.warn('cannot get');
    }
  }

License

MIT © Görkem Başaran

Made with create-react-native-library

Keywords

react-native

FAQs

Package last updated on 07 Aug 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts