feat: add gallery service and ML depth estimation placeholder
Media library access via new expo-media-library Query API, image resize for wallpaper export, and MiDaS depth map service stub for V1.5.
This commit is contained in:
50
src/services/media/gallery.service.ts
Normal file
50
src/services/media/gallery.service.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import * as MediaLibrary from "expo-media-library";
|
||||
import * as ImageManipulator from "expo-image-manipulator";
|
||||
import { Dimensions } from "react-native";
|
||||
|
||||
const { width: SCREEN_WIDTH, height: SCREEN_HEIGHT } = Dimensions.get("screen");
|
||||
|
||||
export async function requestGalleryPermission(): Promise<boolean> {
|
||||
const { status } = await MediaLibrary.requestPermissionsAsync();
|
||||
return status === "granted";
|
||||
}
|
||||
|
||||
export async function getRecentPhotos(
|
||||
count: number = 50,
|
||||
offset: number = 0
|
||||
): Promise<{ assets: MediaLibrary.Asset[]; hasMore: boolean }> {
|
||||
const query = new MediaLibrary.Query()
|
||||
.eq(MediaLibrary.AssetField.MEDIA_TYPE, MediaLibrary.MediaType.IMAGE)
|
||||
.orderBy({
|
||||
key: MediaLibrary.AssetField.CREATION_TIME,
|
||||
ascending: false,
|
||||
})
|
||||
.limit(count)
|
||||
.offset(offset);
|
||||
|
||||
const assets = await query.exe();
|
||||
|
||||
return {
|
||||
assets,
|
||||
hasMore: assets.length === count,
|
||||
};
|
||||
}
|
||||
|
||||
export async function prepareImageForWallpaper(
|
||||
uri: string
|
||||
): Promise<string> {
|
||||
const result = await ImageManipulator.manipulateAsync(
|
||||
uri,
|
||||
[
|
||||
{
|
||||
resize: {
|
||||
width: SCREEN_WIDTH * 2,
|
||||
height: SCREEN_HEIGHT * 2,
|
||||
},
|
||||
},
|
||||
],
|
||||
{ compress: 0.95, format: ImageManipulator.SaveFormat.JPEG }
|
||||
);
|
||||
|
||||
return result.uri;
|
||||
}
|
||||
Reference in New Issue
Block a user