Skip to content
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

이미지 리사이징 유틸 만들기 #167

Merged
merged 2 commits into from
Jan 26, 2022
Merged

이미지 리사이징 유틸 만들기 #167

merged 2 commits into from
Jan 26, 2022

Conversation

SeojinSeojin
Copy link
Member

⛓ Related Issues

📋 작업 내용

  • 현재 클라이언트의 브라우저를 확인하는 유틸 (@utils/browser.ts) 만들어둠
  • 이미지를 리사이징해주는 유틸 (@utils/image.ts) 만들어둠

📌 PR Point

무슨 이유로 어떻게 코드를 변경했는지

  • 이미지 업로드 시 특정 확장자를 받기 위한 과정에서 accept 속성이 잘 동작하도록 바꾸어둠
  • 이미지 업로드 시 브라우저가 Internet Explorer이 아닌 경우 리사이징하여 파일이 설정되도록 변경해둠

어떤 위험이나 우려가 발견되었는지

  • byteString을 만들 때 사용하는 함수인 atob, unescape는 deprecate되었다고 뜨지만, 대체할 수 있는 함수를 못 찾았습니다..

🔬 Reference

https://developer.mozilla.org/en-US/docs/Web/API/createImageBitmap
https://blog.naver.com/PostView.nhn?blogId=okskmk2&logNo=221763461417&parentCategoryNo=&categoryNo=148&viewDate=&isShowPopularPosts=false&from=postView
https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/drawImage
https://stackoverflow.com/questions/27159179/how-to-convert-blob-to-file-in-javascript

@SeojinSeojin SeojinSeojin added the feature 🎄 기능 개발 label Jan 25, 2022
@SeojinSeojin SeojinSeojin self-assigned this Jan 25, 2022
@SeojinSeojin
Copy link
Member Author

울 웹쁜이 고생많았어 ! 여기서 미리보기로 보면서 쉬어~ 다른 웹쁜이들한테도 자랑해줘~

Copy link
Member

@100Gyeon 100Gyeon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

canvas도 쓰고 잘했네 👏🏻 atob, unescape 관련해서 나도 찾아볼게 !!

Comment on lines +3 to +16
if (agent.indexOf('chrome') !== -1) return 'Chrome';
if (agent.indexOf('opera') !== -1) return 'Opera';
if (agent.indexOf('staroffice') !== -1) return 'Star Office';
if (agent.indexOf('webtv') !== -1) return 'WebTV';
if (agent.indexOf('beonex') !== -1) return 'Beonex';
if (agent.indexOf('chimera') !== -1) return 'Chimera';
if (agent.indexOf('netpositive') !== -1) return 'NetPositive';
if (agent.indexOf('phoenix') !== -1) return 'Phoenix';
if (agent.indexOf('firefox') !== -1) return 'Firefox';
if (agent.indexOf('safari') !== -1) return 'Safari';
if (agent.indexOf('skipstone') !== -1) return 'SkipStone';
if (agent.indexOf('netscape') !== -1) return 'Netscape';
if (agent.indexOf('mozilla/5.0') !== -1) return 'Mozilla';
if (agent.indexOf('msie') !== -1) return 'Internet Explorer';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

브라우저 다양한 거 새삼 느낀다.. 익스플로러도 챙겼넹 ㅋㅋㅋㅋ

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

사실 반 넘게 안 쓰는데 누가 저렇게 해놨길래 가져왔어요잉

Comment on lines +7 to +10
const { dWidth, dHeight } = getWidthHeight(imageBitmap, maxSquare);
canvas.width = dWidth;
canvas.height = dHeight;
context.drawImage(imageBitmap, 0, 0, dWidth, dHeight);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dWidth랑 dHeight가 뭔가 했는데 destination의 d구나..!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

공식 문서에 변수 이름이 dWidth랑 dHeight로 되어 있어가지구 그렇게 하였으..!!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 경우에는 한번 만들어놓고 갖다쓰는 유틸 함수라 어엄청 중요하지는 않지만 만약 비슷한 경우가 있다면 나는 그래도 풀어서 쓰는게 좋지 않나 생각! 문서 보지 않은 사람도 이해할 수 있는게 더 좋은 것 같아

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

얍얍..!! 다른 곳에서 많이 export되는 친구들을 쓸 때에는 유의하겠어유..!!

Comment on lines -37 to +48
alert('이미지 파일을 첨부해주세요');
fireToast({ content: '이미지 파일을 첨부해주세요' });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alert 대신에 토스트 쓴 거 잘했다 !!! 👍🏻

Copy link
Member

@NamJwong NamJwong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

리뷰가 늦어서 죄송합니다,,🙏💧 왜 IE는 제외하고 리사이징 하나요??

setFileThumbnail(URL.createObjectURL(file));
if (!file) return fireToast({ content: '이미지 파일을 첨부해주세요' });
if (file.name.match(imgFileForm)) {
if (checkBrowser('Internet Explorer')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checkBrowser 여기에 쓰려고 만들었구나~ 앞으로 또 유용하게 쓸 일 있을 것 같아!!

Copy link
Member

@Hyoin-Kim Hyoin-Kim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생많았어!

@SeojinSeojin
Copy link
Member Author

리뷰가 늦어서 죄송합니다,,🙏💧 왜 IE는 제외하고 리사이징 하나요??

IE에서는 createBitmap 함수가 없기 때문입니다!! 그럼 안 정의된 함수라고 오류가 나기 때문에 그렇게 처리해두었어유

@SeojinSeojin SeojinSeojin merged commit 54f50b8 into dev Jan 26, 2022
@100Gyeon 100Gyeon deleted the feat/#165 branch January 26, 2022 16:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature 🎄 기능 개발
Projects
None yet
Development

Successfully merging this pull request may close these issues.

이미지 리사이징
4 participants