Verwenden Sie die Konfigurationsvariablen unter den Importen, um einen Trockenlauf durchzuführen.
import com.dev5310.imageresizer.support.webp.ImageDimensionSetter
import info.magnolia.cms.util.QueryUtil
import info.magnolia.dam.core.config.DamCoreConfiguration
import info.magnolia.dam.jcr.AssetNodeTypes
import info.magnolia.dam.jcr.DamConstants
import info.magnolia.dam.jcr.JcrAsset
import info.magnolia.dam.jcr.JcrAssetProvider
import info.magnolia.jcr.util.PropertyUtil
import info.magnolia.objectfactory.Components
import javax.jcr.Node
import javax.jcr.NodeIterator
import javax.jcr.Session
final boolean printFoundWebpImages = true
final boolean setAssetDimensions = false
final boolean save = false
final String targetMimeType = "image/webp"
final JcrAssetProvider jcrAssetProvider = new JcrAssetProvider(Components.getComponent(DamCoreConfiguration.class))
final Session session = ctx.getJCRSession(DamConstants.WORKSPACE)
println()
final NodeIterator search = QueryUtil.search(DamConstants.WORKSPACE, "SELECT * FROM [mgnl:asset]")
search.forEachRemaining(item -> {
final Node node = (Node) item
if (!node.hasNode(AssetNodeTypes.AssetResource.RESOURCE_NAME)) {
return;
}
final Node resourceNode = node.getNode(AssetNodeTypes.AssetResource.RESOURCE_NAME)
final String mimeType = PropertyUtil.getString(resourceNode, AssetNodeTypes.AssetResource.MIMETYPE, "Not Set")
final long width = PropertyUtil.getLong(resourceNode, AssetNodeTypes.AssetResource.WIDTH, -1L)
final long height = PropertyUtil.getLong(resourceNode, AssetNodeTypes.AssetResource.HEIGHT, -1L)
if (printFoundWebpImages && targetMimeType == mimeType) {
print("MIME Type: " + mimeType)
print(" - ")
print("Width: " + width)
print(" - ")
print("Height: " + height)
print(" - ")
print(node)
println()
}
if (setAssetDimensions && targetMimeType == mimeType) {
final JcrAsset jcrAsset = new JcrAsset(jcrAssetProvider, node)
final boolean success = ImageDimensionSetter.tryToSetMissingOrWrongAssetDimensions(jcrAsset)
if (success) {
println("Successfully set dimensions of asset: " + node)
} else {
println("Failed to set dimensions of asset: " + node)
}
}
})
if (save && session.hasPendingChanges()) {
session.save()
}
session.logout() // To prevent unclosed session detected stack trace
"done"