AEM Page Image in Page Properties Doesn't Apply a sling:resourceType - aem

Using Adobe Experience Manager 5.6.1 (AEM) (Formerly CQ5) I am trying to create a new tab similar to the Image tab in Page Properties. It would be titled "Logo".
I basically just copied the Image tab to create a logo tab and renamed the paths to reflect the logo purpose. For instance, I set the fileReferenceParamater to ./logo/fileReference and requestSuffix to /logo.img.png.
When I edit the properties, I can drag an image into the tab just as I can with the "Image" tab, however, the image never appears there. I am guessing this is because the default image handler is not picking up the request. The error is:
Cannot serve request to
/content/my-site/home-page/en_us/jcr:content/logo.img.png in
org.apache.sling.servlets.get.DefaultGetServlet
When I looked at the content node there was no sling:resourceType. When I added a resource type of foundation/components/adaptiveimage then it worked. However, I noticed that the "Image" node didn't have a sling:resourceType. I guess the img.png.java servlet in the foundation page is handling that request.
I tried creating a logo.img.png.jsp file in my page component to handle the request, but that didn't seem to work.
How can I get AEM to either add the sling:resourceType or to handle the request?

I was facing the similar problem and I found a simpler way to resolve. All you need to do is to add a hidden xtype under the your logo image as below:
<yourlogo
jcr:primaryType="cq:Widget"
<-- other properties -->
xtype="html5smartimage">
<items jcr:primaryType="cq:WidgetCollection">
<resType
jcr:primaryType="cq:Widget"
ignoreData="{Boolean}true"
name="./logo/sling:resourceType"
value="foundation/components/image"
xtype="hidden"/>
</items>
</yourlogo>

Well, after some time experimenting, this is what I ended up doing to get this to work. If there is an easier way, I would be happy to know it.
First, I copied the /libs/foundation/components/page/img.png.java file and added it to my compiled package with some modifications.
#SlingServlet(
resourceTypes = "sling/servlet/default",
selectors = "imgnode",
extensions = {"png","jpg","jpeg","gif"},
methods = "GET"
)
public class SimpleImageServlet extends AbstractImageServlet {
Where img.png.java had the following line:
Image image = new Image(c.resource, "image");
I changed it to:
Image image = new Image(c.resource);
This relies on SCR annotations to generate the OSGi configuration so that this servlet will handle image requests having the imgnode selector. Instead of looking for a child image node it just expects the current resource to be an image.
Second, I added a component to the body.jsp overlay of the page component, like so.
<cq:include path="logo" resourceType="/apps/my-site/components/logo" />
This maps the logo path to a component for rendering.
Third, within the logo.jsp on the component I set the selector to imgnode rather than img.
Image img = new Image(resourcePage, "logo");
img.setSelector("imgnode");
I believe this step would be similar if the adaptiveimage were overlayed. You just need to render out URLs that include the imgnode selector.
Fourth, I setup the logo image dialog tab in page properties to use the expected requestSuffix and set the other properties to point to the logo sub-node.
Examples:
requestSuffix = "/logo.imgnode.png"
fileReferenceParameter = "./logo/fileReference"
Fifth, I made sure that the image dialog tab for the /apps/my-site/components/logo component pointed to itself.
Examples:
requestSuffix = ".imgnode.png"
fileReferenceParameter = "./fileReference"
Now whether it is in page properties, component editing, or final rendering, the image is handled appropriately.

this is a bit of a nuisance with using the image widget controls--only the image component nicely handles the data, and the servlet that handles ".img" is tied to the image component resourceType.
the easiest thing is to just use the value of the fileReference property instead of referencing the image as part of the page. since you're using assets from DAM, this is a reasonable approach.
this doesn't address the issue with a user uploading an image directly. i wanted to suggest having a hidden field like "./logo/sling:resourceType", but testing that locally resulted in an error when trying to save the dialog.
another approach is the following:
<sling:include resourceType="foundation/components/adaptiveimage" resource="${resource.path}/logo" />
(assuming resource is jcr:content). this is effectively the same as adding a sling:resourceType, but there are at least 2 downsides:
the image becomes authorable at that point as opposed to in the dialog
this method only works for rendering a normal tag. it won't work for any sort of background image

Related

How to add images in Protege

How can I describe class instances with images (e.g. abc.png) and display them inside Protege 5.2.0? I have read the tutorial which uses widgets, but the Forms tab is no longer available in current version of Protege-Owl.
There is a project which intends to provide such ontology : Schema.org.
It is also possible to fully describe a picture thank to the use a of metadata ontology (ISO, ...).
schema:image annotation property may provide what you intend to do.
For annotation values that are URLs that point to images, Protégé displays thumbnails of the images.
More info: https://github.com/protegeproject/protege/issues/315.
Update
You should add the schema:image annotation property (or another suitable annotation property) first:
You can add pictures both for classes and instances.
Be aware until this moment you only can add picture from the web.
I'm going to show you how to add a picture for a class.
First go to Annotation tab and click on + button:
A window will be opened. At this window, you should add schema:image as an annotation property:
After adding schema:image, go to IRI Editor tab at the same window and paste the picture URL into the box (for copying the picture URL, right-click on the image on the web and then click on copy image address):
By clicking on OK you can see the thumbnail of the picture:
Now if you click on this thumbnail, the full image will be opened in a new tab in your browser and you can see it in full size.

How can I maintain image class when using mc:edit in a MailChimp template?

I'm trying to create a MailChimp template where an image is editable using mc:edit
Here's the code:
<img class="flexibleImage" mc:edit="top_image">
This seems all good, but once I edit this image using the MailChimp editor, I lose the original class "flexibleImage" and all other class and style info related to that img element.
How can I create a template with an editable image and maintain (or add) that class?
For anyone else with the problme, this answer is based on a response from MailChimp support:
It looks like it isn't possible to keep a custom class attached to an
editable image. What you could do instead though is apply the class
to the image's containing element. So if the image is in a <div>, add
flexibleImage to the div, and then update your CSS rules to point to
.flexibleImage>img.
This happens because the image you want to edit is inside an mc:repeatable block that in turn is inside another mc:repeatable block
Even four years later this is still an issue.
The other route is to put mc:edit on the parent container, and have images managed through there, but you lose the Image uploader box, which is poor user experience.
You can go into Settings when you have uploaded a new image and put the sizes in there. Not ideal, but Mailchimp is to blame here (no such issue on Campaign Monitor templates).

How to customize the existing image component (map/area functionality) in Adobe Cq5?

There is an image, when I hover on the specific area of a image. I want to show another image in CQ5. Right now I have achieved this using map,area,co-ordinates concept, onmouseover() function I have changed the images. I have got the following things from the dialog from the user.
1)image which needs to appear when hovered
2)co-ordinates of the area.
My question is, I want to avoid getting the co-ordinates from the user. The same map functionality is present in default image component, where should I go and customize the component, so that I can add an extra textfield in the component to just get the image path which needs to change on hover,and I want to add the mouseover functionality as well.
Can someone please help?
Thanks in advance.
When I add an image map to an image dialog, I get the following outputted in Author mode:
<div class="genericImage cq-element-par_47image" id="cq-gen25">
<img title="Triangle - Equilateral" usemap="#map_X" src="image">
<map name="map_X" id="cq-gen117">
<area shape="rect" coords="25,34,209,151" href="/path.html">
</map>
</div>
Going by /libs/foundation/components/image/image.jsp, the <map> and the <image> are all rendered out by the drawOut() method of com.day.cq.wcm.foundation.Image.
If you want to change how the map is outputted, you would need to replace this method with your own code. The details of the map itself though are saved on the image node as a regular property called imageMap, so there's it's quite possible to:
Overlay the image component
Modify your version of the JSP (apps/foundation/components/image/image.jsp) to output the map, the href and the image as you need it (using ${properties.imageMap} for the map/link and ${properties.fileReference} for the image reference)
Write some CSS/JS to overlay your image from the href on hover.

Can't get Image to load, even though it's added to RootPanel?

I want to display an "img" element as a child of a panel. Should we be using the Image widget for this? I'm doing the following:
Image img = new Image();
img.getElement().getStyle().setWidth(80, Style.Unit.PX);
img.getElement().getStyle().setHeight(80, Style.Unit.PX);
// add it to a panel, which eventually gets added to the root panel.
somePanel.add(img);
// set the url
img.setUrl("stuff/test.png");
This works fine on FF. When I run the same code in mobile safari, the images never load. I've added a LoadHandler to the Image instance. I can see that on FF, the event callbacks are triggered. But on mobile safari, they're never triggered.
I recall that an Image must be added to the RootPanel in order for it to ever load, but I am indeed doing that. What else could be causing this? I'm sure the png resource is located correctly.
Thanks
Rule of thumb: always use absolute URLs, possibly using GWT.getModuleBaseURL(), GWT.getHostPageBaseURL() or GWT.getModuleBaseForStaticFiles() as a prefix:
img.setUrl(GWT.getHostPageBaseURL() + "stuff/test.png");
This is because GWT code runs in an iframe and is loaded from within a subfolder, and browsers differ in behavior on whether to use the host page or the iframe URL to resolve relative URLs.

Wicket NonCachingImage Causing Page Constructor invoked twice

I have an img tag on a wicket page and I add image as following:
NonCachingImage banner = NonCachingImage(id, imageResource)
now i also add attributes like: banner.add(new AttributeModifier("width",...
Now my page constructor is getting invoked twice. If for testing I also add
banner.add(new AttributeModifier("src", new Model<String>("test")
constructor would be invoked only once but the image would not be rendered. Please suggest me how can i render the correct image from org.apache.wicket.Resource and make the constructor getting invoked only once.
Would appreciate if you can direct me to specific examples.
In some browsers, <img> tags that are rendered with src="" (no url) the browser will submit a request to the current url in search of the image. If your imageResource is resolving to an empty url path then this would occur. Further, this would not happen if after creating the NonCachingImage you added an AttributeModifier which would override the generated src attribute with a value of "test" as the value would no longer be empty.