Skip to content

Commit

Permalink
fix rotation of selfies
Browse files Browse the repository at this point in the history
  • Loading branch information
jbilcke-hf committed Oct 17, 2024
1 parent d249624 commit 4d0b778
Show file tree
Hide file tree
Showing 8 changed files with 1,714 additions and 132 deletions.
Binary file modified client/bun.lockb
Binary file not shown.
1,504 changes: 1,504 additions & 0 deletions client/package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"lucide-react": "^0.446.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-icons": "^5.3.0",
"tailwind-merge": "^2.5.2",
"tailwindcss": "^3.4.13",
"tailwindcss-animate": "^1.0.7",
Expand Down
9 changes: 5 additions & 4 deletions client/src/app.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useState, useEffect, useRef, useCallback, useMemo } from 'react';
import { Download } from 'lucide-react';
import { FiDownload } from 'react-icons/fi';
import { PiImageSquare } from 'react-icons/pi';

import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert';
import { truncateFileName } from './lib/utils';
Expand Down Expand Up @@ -118,16 +119,16 @@ export function App() {
isMediaPipeReady ? 'bg-slate-600 hover:bg-slate-500' : 'bg-slate-500 cursor-not-allowed'
} focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-slate-500 shadow-xl`}
>
<Spinner />
{imageFile ? truncateFileName(imageFile.name, 32) : (isMediaPipeReady ? 'Choose a portrait photo' : 'Initializing...')}
<PiImageSquare className="w-6 h-6 mr-2" />
{imageFile ? `Replace` : (isMediaPipeReady ? 'Choose a portrait photo' : 'Initializing...')}
</label>
</div>
{previewImage && (
<button
onClick={handleDownload}
className="inline-flex items-center px-3 h-10 border border-transparent text-sm font-medium rounded-md text-white bg-zinc-600 hover:bg-zinc-500 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-zinc-500 shadow-xl"
>
<Download className="w-4 h-4 mr-2" />
<FiDownload className="w-5 h-5 mr-2" />
Download
</button>
)}
Expand Down
2 changes: 1 addition & 1 deletion client/src/hooks/useMainStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -432,5 +432,5 @@ export const useMainStore = create<ImageState>((set, get) => ({
// console.error('Error modifying image:', error);
setError('Failed to modify image');
}
}
},
}))
2 changes: 1 addition & 1 deletion client/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export type OnServerResponseParams = {
image?: Blob
error?: string
loaded?: {
i: string
u: string
} & {
c: number[] //center - 2x1
s: number // size - scalar
Expand Down
5 changes: 4 additions & 1 deletion engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import numpy as np
import torch
import torch.nn.functional as F
from PIL import Image
from PIL import Image, ImageOps

from liveportrait.config.argument_config import ArgumentConfig
from liveportrait.utils.camera import get_rotation_matrix
Expand Down Expand Up @@ -66,6 +66,9 @@ def __init__(self, live_portrait):
async def load_image(self, data):
image = Image.open(io.BytesIO(data))

# keep the exif orientation (fix the selfie issue on iphone)
image = ImageOps.exif_transpose(image)

# Convert the image to RGB mode (removes alpha channel if present)
image = image.convert('RGB')

Expand Down
Loading

0 comments on commit 4d0b778

Please sign in to comment.