Skip to content

Commit

Permalink
feat: Add Crop Factor Mode (#242)
Browse files Browse the repository at this point in the history
  • Loading branch information
rhea-so committed May 2, 2024
2 parents 09b04f3 + 864c428 commit 325a74a
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 2 deletions.
2 changes: 1 addition & 1 deletion web/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.4.68",
"version": "0.4.69",
"type": "module",
"scripts": {
"dev": "vite",
Expand Down
4 changes: 4 additions & 0 deletions web/src/core/photo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ class Photo {
* @example '24mm'
*/
public get focalLength(): string {
if (localStorage.getItem('focalLengthRatioMode') === 'true') {
const focalLength = parseFloat(this.metadata?.focalLength?.replace(' mm', '') || '0');
return (focalLength * parseFloat(localStorage.getItem('focalLengthRatio') || '1')).toFixed(0) + 'mm';
}
return localStorage.getItem('focalLength35mmMode') === 'false' ? this.metadata.focalLength || '' : this.metadata.focalLengthIn35mm || '';
}

Expand Down
2 changes: 2 additions & 0 deletions web/src/locales/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
"root.settings.quality": "Quality",
"root.settings.fix-image-width": "Fix Image Width",
"root.settings.focal-length-35mm-mode": "Focal Length 35mm Mode",
"root.settings.focal-length-ratio": "Crop Factor",
"root.settings.focal-length-ratio-mode": "Fixed Crop Factor",
"root.settings.disable-exposure-meter": "Disable Exposure Meter",
"root.settings.image-width": "Image Width (px)",
"root.settings.fix-watermark": "Add Watermark",
Expand Down
2 changes: 2 additions & 0 deletions web/src/locales/translations/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
"root.settings.quality": "画質",
"root.settings.fix-image-width": "画像幅を固定",
"root.settings.focal-length-35mm-mode": "35mm換算焦点距離",
"root.settings.focal-length-ratio": "焦点距離比率",
"root.settings.focal-length-ratio-mode": "焦点距離比率モード",
"root.settings.disable-exposure-meter": "露出計を無効化",
"root.settings.image-width": "画像幅(px)",
"root.settings.fix-watermark": "ウォーターマーク",
Expand Down
2 changes: 2 additions & 0 deletions web/src/locales/translations/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
"root.settings.quality": "품질",
"root.settings.fix-image-width": "사진 너비 고정",
"root.settings.focal-length-35mm-mode": "35mm 환산 화각 표시",
"root.settings.focal-length-ratio": "크롭 팩터",
"root.settings.focal-length-ratio-mode": "크롭 팩터 강제 변경",
"root.settings.disable-exposure-meter": "노출계 표시 끄기",
"root.settings.image-width": "사진 너비 (px)",
"root.settings.fix-watermark": "워터마크 설정",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import CameraIcon from '../../../icons/camera.icon';

const FocalLength35mmModeListItem = () => {
const { t } = useTranslation();
const { focalLength35mmMode, setFocalLength35mmMode } = useStore();
const { focalLengthRatioMode, focalLength35mmMode, setFocalLength35mmMode } = useStore();

if (focalLengthRatioMode) return null;

return (
<ListItem
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { ListInput, ListItem, Toggle } from 'konsta/react';
import { useStore } from '../../../store';
import { useTranslation } from 'react-i18next';
import CameraIcon from '../../../icons/camera.icon';

const FocalLengthRatioModeListItem = () => {
const { t } = useTranslation();
const { focalLengthRatioMode, setFocalLengthRatioMode, focalLengthRatio, setFocalLengthRatio } = useStore();

return (
<>
<ListItem
title={t('root.settings.focal-length-ratio-mode')}
media={<CameraIcon size={26} />}
after={<Toggle checked={focalLengthRatioMode} onChange={() => setFocalLengthRatioMode(!focalLengthRatioMode)} />}
/>

{focalLengthRatioMode && (
<ListInput
floatingLabel
info={`35mm FF = 1, APS-C = 1.5, APS-C(Canon) = 1.6, Four Thirds = 2, 1" = 2.7`}
label={t('root.settings.focal-length-ratio')}
type="number"
value={focalLengthRatio}
onChange={(e) => setFocalLengthRatio(e.target.value)}
/>
)}
</>
);
};

export default FocalLengthRatioModeListItem;
2 changes: 2 additions & 0 deletions web/src/pages/setting/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import PrivacyPolicyListItem from './components/privacy-policy.list-item';
import { useStore } from '../../store';
import SponsorKakaopayListItem from './components/sponsor-kakaopay.list-item';
import SponsorsListItem from './components/sponsors.list-item';
import FocalLengthRatioModeListItem from './components/focal-length-ratio-mode.list-item';

const ExportSettingsPage = () => {
const { t } = useTranslation();
Expand All @@ -48,6 +49,7 @@ const ExportSettingsPage = () => {
<ExportToJpegListItem />
<QualityListItem />
<FixImageWidthListItem />
<FocalLengthRatioModeListItem />
<FocalLength35mmModeListItem />
<RatioListItem />
</List>
Expand Down
20 changes: 20 additions & 0 deletions web/src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ type Store = {
focalLength35mmMode: boolean;
setFocalLength35mmMode: (focalLength35mmMode: boolean) => void;

focalLengthRatioMode: boolean;
setFocalLengthRatioMode: (focalLengthRatioMode: boolean) => void;

focalLengthRatio: number;
setFocalLengthRatio: (focalLengthRatio: number) => void;

disableExposureMeter: boolean;
setDisableExposureMeter: (disableExposureMeter: boolean) => void;

Expand Down Expand Up @@ -236,6 +242,20 @@ const useStore = create<Store>((set) => ({
return { focalLength35mmMode };
}),

focalLengthRatioMode: localStorage.getItem('focalLengthRatioMode') === 'true',
setFocalLengthRatioMode: (focalLengthRatioMode: boolean) =>
set(() => {
localStorage.setItem('focalLengthRatioMode', focalLengthRatioMode.toString());
return { focalLengthRatioMode };
}),

focalLengthRatio: parseFloat(localStorage.getItem('focalLengthRatio') || '1'),
setFocalLengthRatio: (focalLengthRatio: number) =>
set(() => {
localStorage.setItem('focalLengthRatio', focalLengthRatio.toString());
return { focalLengthRatio };
}),

disableExposureMeter: localStorage.getItem('disableExposureMeter') === 'true',
setDisableExposureMeter: (disableExposureMeter: boolean) =>
set(() => {
Expand Down

0 comments on commit 325a74a

Please sign in to comment.