Skip to content

Commit

Permalink
fix: Thumbnail image too big (#1578)
Browse files Browse the repository at this point in the history
* fix: Thumbnail image too big

* chore: Change size of assets' thumbnails

Co-authored-by: Juan Cazala <juan@decentraland.org>
  • Loading branch information
LautaroPetaccio and cazala committed Sep 21, 2021
1 parent dc7688e commit a013996
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 14 deletions.
4 changes: 3 additions & 1 deletion src/components/AssetImporter/AssetImporter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,9 @@ export default class AssetImporter<T extends MixedAssetPack = RawAssetPack> exte
let mappings = rawMappingsToObjectURL(outFile.asset.contents)
const { image, info } = await getModelData(mappings[outFile.asset.model], {
mappings,
thumbnailType: outFile.asset.category === GROUND_CATEGORY ? ThumbnailType.TOP : ThumbnailType.DEFAULT
thumbnailType: outFile.asset.category === GROUND_CATEGORY ? ThumbnailType.TOP : ThumbnailType.DEFAULT,
width: 256,
height: 256
})
revokeMappingsObjectURL(mappings)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ export default class SingleAssetEditor<T extends RawAsset | Asset> extends React

const { image } = await getModelData(mappings[asset.model], {
mappings,
thumbnailType: ground ? ThumbnailType.TOP : ThumbnailType.DEFAULT
thumbnailType: ground ? ThumbnailType.TOP : ThumbnailType.DEFAULT,
width: 256,
height: 256
})
revokeMappingsObjectURL(mappings)

Expand Down
6 changes: 4 additions & 2 deletions src/components/Modals/CreateItemModal/CreateItemModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -462,8 +462,8 @@ export default class CreateItemModal extends React.PureComponent<Props, State> {
} else {
const url = URL.createObjectURL(contents[model])
const { image, info } = await getModelData(url, {
width: 256,
height: 256,
width: 512,
height: 512,
extension: getExtension(model) || undefined,
engine: EngineType.BABYLON
})
Expand Down Expand Up @@ -495,6 +495,8 @@ export default class CreateItemModal extends React.PureComponent<Props, State> {
} else {
const url = URL.createObjectURL(contents![model!])
const { image } = await getModelData(url, {
width: 512,
height: 512,
thumbnailType: getThumbnailType(category),
extension: (model && getExtension(model)) || undefined,
engine: EngineType.BABYLON
Expand Down
10 changes: 2 additions & 8 deletions src/lib/getScreenshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,9 @@ export async function getScreenshot(url: string, options: Partial<Options> = {})
const center = parent.getBoundingInfo().boundingBox.center.multiply(scale)
parent.position.subtractInPlace(center)

// render
const imageFuture = future<string>()
const imageResolver = (data: string) => imageFuture.resolve(data)
Tools.CreateScreenshotUsingRenderTarget(engine, camera, 1024, imageResolver, undefined, undefined, true)
const image = await imageFuture

// remove dom element
document.body.removeChild(canvas)

// return image
return image
// render
return Tools.CreateScreenshotUsingRenderTargetAsync(engine, camera, { width, height }, undefined, undefined, true)
}
5 changes: 3 additions & 2 deletions src/modules/item/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
InitializeItem
} from './types'
import { sortByCreatedAt } from 'lib/sort'
import { NO_CACHE_HEADERS } from 'lib/headers'

export const MAX_FILE_SIZE = 2097152 // 2MB
export const MAX_NFTS_PER_MINT = 50
Expand Down Expand Up @@ -58,7 +59,7 @@ export function getBodyShapeType(item: Item): BodyShapeType {
} else if (hasFemale) {
return BodyShapeType.FEMALE
} else {
throw new Error(`Couldn\'t find a valid representantion: ${JSON.stringify(item.data.representations, null, 2)}`)
throw new Error(`Couldn\'t find a valid representation: ${JSON.stringify(item.data.representations, null, 2)}`)
}
}

Expand Down Expand Up @@ -153,7 +154,7 @@ export function toItemObject(items: Item[]) {

export async function generateImage(item: Item, width = 256, height = 256) {
// fetch thumbnail
const response = await fetch(getContentsStorageUrl(item.contents[item.thumbnail]))
const response = await fetch(getContentsStorageUrl(item.contents[item.thumbnail]), { headers: NO_CACHE_HEADERS })
if (!response.ok) throw new Error(`Error generating the image: ${response.statusText}`)

const thumbnail = await response.blob()
Expand Down

1 comment on commit a013996

@vercel
Copy link

@vercel vercel bot commented on a013996 Sep 21, 2021

Choose a reason for hiding this comment

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

Please sign in to comment.