How can set Element Id for a image which is accessed using ClientBundle in GWT? - gwt

In GWT, I need to set element id for a image which will be accessed using ClientBundle.
For eg. #Source("logo.png")
ImageResource logo();
Instead of Image I'm calling this logo(). But I want to set element Id for logo.png.
Is it possible?

Resources resources = GWT.create(Resources.class);
Image img = new Image(resources.logo());
img.getElement().setID("ID");
Is it what you want ?

Related

how to filter asset and meta-data property values using query builder in aem

type:nt:unstructured
path=/content/dam/en_us
node=jcr:content
group.1_property=Cmg_name
group.1_property.operation=exists
group.1_property.value=Web Standard
I have assets like pdf and images inside \content\dam\en-us and also i have meta data for respective assets .i want to get pdf or image by asset metadata property values .but i am notable to get exact output.I have asset c012666.png inside jcr:cotent inside metadata.now, if give property value i have to get that pdf file.so, pls can any one help???
if you want to list the properties of a hit you have to use p.hits = full. And if you want to list all it's children you have to use the p.nodedepth = AMOUNT_OF_SUBLEVELS.
For example the query http://localhost:4502/bin/querybuilder.json?p.hits=full&property=jcr%3atitle&property.value=Default%20Design&p.nodedepth=2
will list the properties of the the node called "Default design" and also list the children of it
Hope that this suits your needs
Here's some documentations https://hashimkhan.in/2015/12/02/query-builder/

EaselJS export DisplayObject as bitmap

I have a EaselJS Container object and I want to export its contents (children Bitmaps) as an image (similar to what you would do with ActionScript PNGEncoder.encode).
Is this possible? I have other object present that I don't want to export so exporting the full <canvas> wouldn't work.
You can use the getCacheDataURL method to export any cached DisplayObject to an image data url.
http://jsfiddle.net/lannymcnie/jqfgynve/1/
bmp.cache(0,0,image.width,image.height);
var url = bmp.getCacheDataURL();
var img = new Image();
img.src = url;
Any time you cache an image, a canvas is created that is drawn in place of the image. This method calls toDataURL() on the cache-canvas, generating a data URL that can be passed to the source of an image.
Note that the toDataURL is not a super performant API.

How to add an id to image in typo3?

I am struggling with typo3. I want to add a default id to a particular image uploaded in a section by user.
My backend layout create a section with colPos = 1.
In this section user can upload one image, which will have id of
bg-img
I have cleared default rendering of image by this code:
tt_content.image.20.1.layout.default.element = <img src="###SRC###" ###ALTPARAMS###>
My template code is like this:
page.10.subparts {
HEADERIMG<styles.content.get
HEADERIMG.select.where = colPos= 1
}
How to do that?
I don´t think having multiple images with the same id on a page is correct HTML, as ID´s should always be unique per page. Use the class attribute instead. With the following code you can specify image params.
tt_content.image.20.1.params = class="my-class" id="bg-img"

GWT: I want to create a custom annotation to replace #Source

I have a ClientBundle in which I am referencing a bunch of icons as ImageResource's
public interface DefaultCMSResources extends ClientBundle {
String baseImgLoc = "com/jorsek/ui/client/style/images/base/";
String baseIconLoc = "com/jorsek/ui/client/style/images/icons/";
String fugeIconsLoc = baseIconLoc+"fugue/";
/* Icons */
#Source(fugeIconsLoc+"book-open.png")
ImageResource getBookIcon();
}
For a number of reasons I really don't like having to reference the static file location via the #Source annotation.
I really would like to create a custom annotation like #FugueIcon, which would generate the static path dynamically somewhere. IE:
public interface DefaultCMSResources extends ClientBundle {
/* Icons */
#FugueIcon("book-open")
ImageResource getBookIcon();
}
I was looking through the code for the #Source annotation and nothing popped out at me. I was hoping someone could provide the steps I might take to accomplish this.
Thanks!
The problem with this is that if the file is selected dynamically, the compiler won't know ahead of time what the image will be - it won't know the size, so it can't write proper css for it (if using #sprite in your CssResource) or provide results for the various ImageResource methods. The #Source annotation means that the compiler can know all it needs to about the image before the app has turned into JS, so it can write in that JS details about the image it will have.
Instead, you might want to look at a way to implement that ImageResource method directly - one option would be to instantiate a com.google.gwt.resources.client.impl.ImageResourcePrototype instance, which implements that interface, and lets you specify details about the image that are needed - a name (mostly optional) the url it can be found at, and the position in that url (if you are spriting) as well as the size to use.

Adobe CQ5.5-How to display Page Thumbnail using API

I have configured image for my page using sidekick >Page properties>Images tab. Now I want to fetch my this page image(thumbnail) in one of my jsp. Can someone give me pointers or code snippet for api class and method that I can use to achieve this.
Thanks,
Rajeev
I would suggest using the default image component as an example - /libs/foundation/components/image.
If you're putting your code into a component for your specific page type though, your code should be something like this:
if (currentNode.hasNode("image")) {
String imagePath = currentNode.getNode("image").getPath();
Resource imageRes = resourceResolver.getResource(imagePath);
image = new Image(imageRes);
image.loadStyleData(currentStyle);
image.setSelector(".img");
if (!currentDesign.equals(resourceDesign)) {
image.setSuffix(currentDesign.getId());
}
image.draw(out);
}
Keep in mind though, even though you set an image, it does NOT mean it will show up - if you're using the default page dialog for page properties, it will only show a broken image. That's because there is a bug in CQ where the sling:resourceType property of the image doesn't get set, and thus it won't show up. This is because the .img selector that gets put on the image doesn't know what to do, unless it get's pointed to a resource type with a definition for the .img selector, so it can properly render the image.
I've uploaded a package that you can use as a hotfix for the issue with the default /libs/foundation/components/page component dialog, so that it will actually set the resource type when you upload an image. You can find/download the package from my Google Drive
Hopefully that helps. Let me know if you need more help.
EDIT
If you're trying to get the page properties image from one page on another page, you just need to use a resource resolver. You should have one available to you in CQ, so this would essentially be the code:
Resource imageRes = resourceResolver.getResource(pathFromYourDialog);
Image image = new Image(imageRes);
The rest would be the same - you're just giving it a different path to start from.
I think Nicholaus was more on point with his EDIT answer to your immediate need. If the user is providing you a path to the thumbnail via the dialog (i.e. a DAM image).
You can simply create the image, or if it has DAM information you can load it as a DAM Asset and pull the necessary information.
Image image = new Image();
Resource imageResource = resourceResolver.getResource(imageUrl);
Asset imageAsset = imageResource.adaptTo(Asset.class);
Map<String, Object> valueMap = imageAsset.getMetadata();
long width = Long.parseLong(valueMap.get("tiff:ImageWidth").toString());
long height = Long.parseLong(valueMap.get("tiff:ImageLength").toString());
Object titleObject = valueMap.get("tiff:ImageTitle");
String title = (titleObject == null) ? null : titleObject.toString();
if (title != null)
{
image.setTitle(title);
}
image.setWidth(width);
image.setHeight(height);
image.setUrl(imageUrl);
This is a little long hand for what Nicholaus had suggested, the Image class will create itself based off the Resource you pass it. (actually upvoted Nicholaus for that, have some optimizations we can make).
Another, simpler option would be to just use the src that the user passes through, in the event that all you're doing is setting a thumbnail. I'm guessing you could be safe in doing something like:
in java:
String thumbSrc = properties.get("thumbSrc", "defaultThumbnail.path");
if (!thumbSrc.isEmpty())
{
pageContext("thumbSrc", thumbSrc);
}
in jsp:
<img alt="thumbnail" src="${thumbSrc}"/>
or if you don't want to do anything in the java you could just do something like
<c:if test="${not empty properties.thumbSrc}">
<img alt="thumbnail" src="${properties.thumbSrc}"/>
</c:if>
In order to get the same result as the first part in just jsp, you'd need to wrap it in a choose, because passing it through some processing before sending to view makes it easier to set default values.