A photo manager for VRChat.

Fix image resizing closes #11

phaz.uk f33eb4fe 07aba694

verified
Changed files
+38 -2
src
Components
css
+36 -1
src/Components/PhotoViewer.tsx
··· 150 150 }) 151 151 } 152 152 153 + let resizeImage = () => { 154 + let dstWidth; 155 + let dstHeight; 156 + 157 + let imgHeight = imageViewer.height; 158 + let imgWidth = imageViewer.width; 159 + 160 + if( 161 + imgWidth / window.innerWidth < 162 + imgHeight / window.innerHeight 163 + ) { 164 + dstWidth = imgWidth * (window.innerHeight / imgHeight); 165 + dstHeight = window.innerHeight; 166 + } else{ 167 + dstWidth = window.innerWidth; 168 + dstHeight = imgHeight * (window.innerWidth / imgWidth); 169 + } 170 + 171 + imageViewer.style.width = dstWidth + 'px'; 172 + imageViewer.style.height = dstHeight + 'px'; 173 + } 174 + 153 175 onMount(() => { 154 176 utils.set(photoControls, { translateX: '-50%' }); 155 177 utils.set(photoTrayCloseBtn, { translateX: '-50%', opacity: 0, scale: '0.75', bottom: '10px' }); 156 178 utils.set(photoLayerManager, { translateY: '20px', opacity: 0, display: 'none' }); 157 179 158 180 window.addEventListener('keyup', switchPhotoWithKey); 181 + 182 + resizeImage(); 183 + 184 + window.addEventListener('resize', () => resizeImage()); 159 185 160 186 let contextMenuOpen = false; 161 187 window.CloseAllPopups.push(() => { ··· 465 491 <img draggable="false" src="/icon/x-solid.svg"></img> 466 492 </div> 467 493 </div> 468 - <img class="image-container" ref={( el ) => imageViewer = el} /> 494 + 495 + <div style={{ 496 + width: '100%', 497 + height: '100%', 498 + display: 'flex', 499 + "justify-content": 'center', 500 + 'align-items': 'center' 501 + }}> 502 + <img class="image-container" ref={( el ) => imageViewer = el} /> 503 + </div> 469 504 470 505 <div class="prev-button" onClick={() => { 471 506 window.CloseAllPopups.forEach(p => p());
+2 -1
src/css/viewer.css
··· 59 59 } 60 60 61 61 .image-container{ 62 - height: 100%; 62 + max-width: none; 63 + max-height: none; 63 64 background-size: contain !important; 64 65 background-repeat: no-repeat !important; 65 66 background-position: center !important;