Changepic and keep original image size with adjust parameter - docx

I have a template in which I'm attempting to change the source of a picture from Image 1, to Image 2 - yet I want Image 2 to keep the original size it was uploaded to the server in. (I want it in the position of Image 1, but its own dimensions.)
To do this, I figured I needed to use the adjust parameter - which I have attempted. The description for adjust=100% is "The picture is adjusted to be proportional to the original size." - which sounded like what I needed to do.
However, in my docx output, this seems to set the image size to be 100% of page width, rather than related to image size. (In the word image properties, it shows my image to be 208%, so I don't think it's related to my file!)
Is this a bug in opentbs, or have I misunderstood the docs? If so, how should I be doing it, or otherwise, can anyone thing of a work around? I attempted not using adjust at all, however that seems to have the same behaviour as adjust=inside - which I presume is the default.
With the normal thanks for a great tool!
Edit: The Error causing tag is below. I've found the problem reproducible when starting from nothing, and with just an image in the word doc. Word 2010, OpenTBS 1.8.
[onshow.logo;ope=changepic;tagpos=after;adjust=100%]

The problems was caused by the TbsPicAdjust() function expecting the image's dimensions to be provided in points, rather than pixels, as php's getimagesize() function was returning.
It was solved by replacing the two fixed coefficients in the TbsPicGetDim_OpenXML_dml() function with 9,525, rather 12,700 as they were originally coded. (Which would be an appropriate value, if the dimensions were in points, rather than pixels.)
After some research, from what I can see, getimagesize() always returns a size in pixels rather than points, so it looks to me like this could be a potential bug?
Additional Source for coefficient, combined with personal calculations: http://openxmldeveloper.org/discussions/formats/f/15/p/396/933.aspx

Workaround:
It depends if you are using the new (.docx) or old (.doc) style of document. If you have the newer style, I don't know for sure that you can change the image size without putting the tag directly into the XML. The older (VML, I believe) style uses <v:shape> to describe a picture rather than <pic:pic>. With v:shape, you can just put together a CSS-style string that describes the size, etc. of your image. Something like:
$imgStyle = "position:absolute;left:0;top:0;width:800;height:600"
Then you just have a tag next to your changepic tag; something like:
[imgStyle;att=v:shape#style]
The newer style does not use a style string like this to size and position images, the pic:pic element is full of nested tags describing the image so it is harder to get to the details (though you could certainly try). I ended up creating a subtemplate for my image switching because my template is in the new format with compatibility for the old format (so I have to maintain two image blocks). This allows me to maintain the XML directly for the image dimensions, but still be able to edit my main template in Word. I just use a tag in my main template that includes the subtemplate like:
[LineItem.template;block=w:r;file='img.xml']
Separating the manually controlled XML out allows me to edit the main template in Word without damaging the really custom parts. Using this technique though, you may have some trouble with onload/onshow tags in the subtemplate - everything I change in the subtemplate is controlled by a block.

Related

BIRT Report - Multiline text underlined to the full width

I'm trying to create a report with a layout as shown in the picture. The value of each field is underlined to the full width of the report. If it occupies more than one line each line is underlined. And there is also a short comment under the first line explaining the meaning of the field (shown in parentheses).
When we faced the same problem using JasperReports we had to create a custom component for that purpose. Does anyone know what the solution in BIRT might look like?
The only way I can think of is to calculate the line wrapping yourself, eg. converting your long text into a series of single lines.
Say you find a way to do this in a scripted data set, using the long text as an input.
You could then use a table item to render these single lines in the layout; using the bottom border to create the underlines (or possible an empty extra detail row with a top border and a height of 2pt to create nice line spacing).
Now how would this scripted data set look like?
I think when you study the source code of BIRT, you'll probably somewhere find a utility function that calculates the width (in whatever units) of a given text in a given font and size. Maybe this is also somewhere inside java.awt or inside iText (com.lowagie.text).
Then it is possible to call this function from inside Java Script and - with more or less logic - to use this as a basis for your scripted data set. But I think this will take a few hours to code.
If you manage to do this, it'd be nice if you post the solution here.

Is it possible to specify direction when using the ##images/image/tag url form?

Specifically, the default scaling profile uses the 'keep' scale property; see https://github.com/plone/plone.scale/blob/master/plone/scale/scale.py#L62
This scales without cropping.
It's useful to set the plone.allow_sizes registry key to allow custom tags, eg.
http://192.168.15.156:8080/Plone/media/4qrcrmn.jpg/##images/image/tile
However, this doesn't respect the requested size; it simple proportionally scales the image.
I've been digging through the source of https://github.com/plone/plone.app.imaging/blob/master/src/plone/app/imaging/scaling.py#L179 trying to understand what's happening, but there doesn't appear to be a way to override the direction property here?
Is there some other way of doing this, or is the only option to create custom views for the Image type?
I guess this is not possible simply through the url.
You could either generate a tag inside a view (like you said) and crop it to the exact size you need: https://github.com/plone/plone.app.imaging/blob/master/README.rst#new-style-image-scales
Or you could use plone.app.imagecropping. With this package you can edit each uploaded image and crop it to the exact size you defined in the available scales. You can even specify which area of the image should be used for the crop. After this is done the url
http://192.168.15.156:8080/Plone/media/4qrcrmn.jpg/##images/image/tile
Will give you the exact cropped image you have specified for that scale.

Controlling Image Size for Posts in WordPress

I've been playing around with WordPress. As a programmer, the media library seems a little strange to me - but I'm keen to understand how I can achieve what I need with the framework. Cue WordPress enthusiasts...
I need to force my WordPress post images to be a certain size. I'm not talking about the thumbnail size, which I've found can be easily manipulated within the loop, but the images that actually get inserted into a post, amongst the writing and the other media. I have a fixed content width, and I would like the images to reflect that width (uncropped).
Obviously, I could run some sort of Regular Expression that could identify the image tags, and replace them with new sizes, but is there really no other way of forcing image sizes within the post while retaining there position amongst the formatted writing that comes with it?
So far, I'm guessing that there is a CSS property out there that is used by WordPress in all images. At a push, I'm willing to go with this - whatever it may be (answer needed). But I was hoping that their might be some more involved code (perhaps something I could plop into the functions.php file) which could actually force any inserted post images to be a certain width.
Any thoughts on this would be much appreciated.
If that's only about limiting the max width of an image and prevent an image from overflow, you could use the $content_width variable in your theme:
https://wordpress.stackexchange.com/questions/6499/how-to-create-a-conditional-content-width-for-a-wordpress-theme

When to use image and when to use background-image while webdesigning?

I am a hobbyist webdesigner, use html and CSS for testing various website designs. However one particular thing that always confuse me is the decision to make use of image as tag or to use it as background via css or html.
Is their any rule of thumb for this ?
As one of the answers pointed out, you need to make the difference between content and actual page style.
Let me elaborate on that. The purpose of the background-image property is used to define the look of a certain block of your page, be it a div or a p, the key point to take home is that you're defining the page's look. And images in the context of defining the page's design (be that patterns, logos, gradients etc.) should almost never take the explicit form of an img tag. That tag is used to define content images, something linked to the news at hand - something that is unique to a story you're trying to portray.
It's very crucial to differentiate these two concepts because it'll allow you to contemplate a good design independent of the underlying content - as it should be. Uniformal, elegant and precise.
So, in review. Use background-image to define the look of the various blocks that comprise your website and use the classic img tag when you want to add visual content that is context-specific.
The question is it Content or Styling is a good place to draw the line on images.
Will this image be reused? etc.
Do you want the image be part of the document flow, give descriptions to the search engines (alt-text)? Use the img tag.
If you want to place other elements over the image (like text, copyright info), use a background image. You can even combine it by placing an image with transparency over the background image to get some effect.
Furthermore a lot of examples exist where the positioning of background images is used to get performance benefits ("sprites").

How do you add a background image for printing in IE/FF?

In other topics I've found that IE/FF doesn't print background images by default. Now that's a shame, because background images add some possibilities that are very difficult to reproduce with classical <img> tags:
You can align them both horizontally and vertically
You can crop them if they are larger than the target element (which also enables the idea of CSS sprites)
Now, it's not impossible to do, but it will require me to have different HTML layouts for printing and normal page, and the printing layout will be quite overcomplicated (since I'll have to use <table>s to achieve vertical alignment). Also, the benefits of CSS sprites will be lost.
Is there any hope? I gather that #media print doesn't help, but isn't there something else, maybe browser-specific, that would allow one to say: "Yes, this isn't a normal background, it really needs to be there even in print view"?
Not possible. You would have to some how convert your background images to img or use Canvas. Of course using canvas depends on which IE you supporting.
Its a browser setting which restricts the printing of background images. I think the logic behind it was that the vendors wanted to give the users the option of printing background images and ensure that the web developer could not alter these settings through some sort of script.
As a general rule, background images should be reserved for adding to the page design but aren't essential to understanding the content. Therefore it shouldn't matter if they are missing when the page is printed. If something (such as a product shot) is important, then it should be included as an actual image (which has the added bonus of being more accessible).
Could you look at including the image, then hiding it using CSS and duplicating is as a background image (perhaps dynamically using JS)? That way, you can ensure the image itself shows in your print stylesheet, and you get the benefits that having a background image brings. I've created a very simple example here.

Resources