# Copy asset Thumbnail to new Texture2d?

**URL:** <https://forums.unrealengine.com/t/copy-asset-thumbnail-to-new-texture2d/138054>\
**Category:** Editor Scripting\
**Tags:** unreal-engine\
**Created:** [February 12, 2020, 5:17pm UTC](https://forums.unrealengine.com/t/copy-asset-thumbnail-to-new-texture2d/138054 "2020-02-12T17:17:20Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![chpsemail](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/chpsemail/32/496464_2.png) [@chpsemail](https://forums.unrealengine.com/u/chpsemail)\
**Post date:** [June 6, 2022, 11:21am UTC](https://forums.unrealengine.com/t/copy-asset-thumbnail-to-new-texture2d/138054/3 "2022-06-06T11:21:11Z")

</div>

I think if you want to export the thumbnail and import it as a texture assets in python or bp, you need do a little c++ work: export a Blueprint callable function which export the thumbnail as a image, then import it as texture2D assets with python script or bp.

The source of the export function from [JoeRadak](https://forums.unrealengine.com/u/JoeRadak):  
[Exporting Thumbnails to PNGs - Pipeline & Plugins / Editor Scripting - Unreal Engine Forums](https://forums.unrealengine.com/t/exporting-thumbnails-to-pngs/501891)

```auto
	/**.h
	 * Save the Thumbnail of assets to disc.
	 *
	 * @param ObjectPath The specified path of asset
	 * @param	OutputPath Thumbnail output path
	 */
	UFUNCTION(BlueprintCallable, meta = (Keywords = "Python Editor"), Category = "PythonEditor")
	static void SaveThumbnail(FString ObjectPath, FString OutputPath);

```

and the implementation in .cpp

```auto
/**.cpp */
void UPythonBPLib::SaveThumbnail(FString ObjectPath, FString OutputPath)
{
	FAssetRegistryModule& AssetRegistryModule = FModuleManager::Get().LoadModuleChecked<FAssetRegistryModule>(TEXT("AssetRegistry"));
	FAssetData AssetData = AssetRegistryModule.Get().GetAssetByObjectPath(*ObjectPath);
	UObject* MyObject = AssetData.GetAsset();
	if (MyObject)
	{
		FObjectThumbnail* ObjectThumbnail = ThumbnailTools::GenerateThumbnailForObjectToSaveToDisk(MyObject);
		if (ObjectThumbnail)
		{
			IImageWrapperModule& ImageWrapperModule = FModuleManager::Get().LoadModuleChecked<IImageWrapperModule>(TEXT("ImageWrapper"));
			TSharedPtr<IImageWrapper> ImageWrapper = ImageWrapperModule.CreateImageWrapper(EImageFormat::PNG);

			ImageWrapper->SetRaw(ObjectThumbnail->GetUncompressedImageData().GetData(), ObjectThumbnail->GetUncompressedImageData().Num(), ObjectThumbnail->GetImageWidth(), ObjectThumbnail->GetImageHeight(), ERGBFormat::BGRA, 8);
			if (ImageWrapper)
			{
				const TArray64<uint8>& CompressedByteArray = ImageWrapper->GetCompressed();
				FFileHelper::SaveArrayToFile(CompressedByteArray, *OutputPath);
			}
		}
	}
}

```

Then, we can export the thumbnail with python like this:

```auto

    def on_button_ExportThumbnail_click(self):
        print('on_button_ExportThumbnail_click')
        folder = "/Game/YourAssetsFolder"
        asset_paths = unreal.EditorAssetLibrary.list_assets(folder, recursive=True)
        target_folder = r"D:\YouArtSourceFolder"

        for i, asset_path in enumerate(asset_paths):
            asset = unreal.load_asset(asset_path)
            if type(asset) is not unreal.StaticMesh: # change the types
                continue

            name_with_folder = asset_path[len(folder)+1:].split(".")[0]
            target_file_path = os.path.join(target_folder, f"{name_with_folder.replace('/', '_')}.png")
            
            unreal.PythonBPLib.save_thumbnail(asset_path, target_file_path)

```

After that, import the exported thumbnail as texture

```auto
    import_task = unreal.AssetImportTask()
    # set the import_task.filename, destination_path, options and so on
    import_task.filename = texture_path
    # ...
    unreal.AssetToolsHelpers.get_asset_tools().import_asset_tasks([import_task])

```

Hope, that helps.

---

_[View the full topic](https://forums.unrealengine.com/t/copy-asset-thumbnail-to-new-texture2d/138054)._
