-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat/#114 image compression (+webp) #208
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,30 +2,37 @@ import { useState } from "react"; | |
|
||
import { IcAddProfileBtn } from "../../../../asset/icon"; | ||
import { ImgDefaultBigProfile } from "../../../../asset/image"; | ||
import compressImage from "../../../../util/imageCompressor"; | ||
import { St } from "./style"; | ||
|
||
interface ProfileImageProps { | ||
setImage: (file: File) => void; | ||
setProfileImage: (file: File) => void; | ||
} | ||
|
||
const MAX_IMAGE_SIZE = 80 * 2; | ||
|
||
export default function ProfileImage(props: ProfileImageProps) { | ||
const { setImage } = props; | ||
const [imgUrl, setImgUrl] = useState<string>(""); | ||
const { setProfileImage } = props; | ||
const [previewImgUrl, setPreviewImgUrl] = useState(""); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "" 로 string인게 이미 추론되어서, 직접 명시할 필요 없어!! |
||
|
||
const handleImagePatch = async (e: React.ChangeEvent<HTMLInputElement>) => { | ||
if (e.target.files === null) return; | ||
|
||
const selectedImg = e.target.files[0]; | ||
setImgUrl(URL.createObjectURL(selectedImg)); | ||
const compressedSelectedImg = await compressImage(selectedImg, { | ||
maxWidth: MAX_IMAGE_SIZE, | ||
maxHeight: MAX_IMAGE_SIZE, | ||
}); | ||
Comment on lines
+22
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 요로코롬 사용하눈 거구나👀👀 므싯다요😎😎😎😎 |
||
|
||
setImage(selectedImg); | ||
setProfileImage(compressedSelectedImg); | ||
setPreviewImgUrl(URL.createObjectURL(compressedSelectedImg)); | ||
}; | ||
|
||
return ( | ||
<St.ProfileImage> | ||
<St.ImageContainer> | ||
<St.ImageWrapper> | ||
<St.AddImage src={imgUrl ? imgUrl : ImgDefaultBigProfile} alt="프로필" /> | ||
<St.AddImage src={previewImgUrl ? previewImgUrl : ImgDefaultBigProfile} alt="프로필" /> | ||
</St.ImageWrapper> | ||
<St.AddBtnWrapper> | ||
<IcAddProfileBtn /> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
최대치가
*2
인 이유가 있을까요?!?!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
80으로 직접 명시를 해도 좋은데, 레티나 디스플레이 대응 이슈로 인해 2배 정도로 지정하면 좋다고 알아요!!!~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
아하 구렇구나😆😆