Is there a general way to define the size, in percent or pixels, for an image that is linked in org-mode?
Say I have the following link in my .org file:
[[~/images/example.jpg]]
This JPG is way too large, so if I export it to HTML or LaTeX or open it in org-mode with C-c C-o i will only see a fraction of the image.
As of Org 8.0, "Attribute lines now take plists" :
#+attr_html: :width 100px
#+attr_latex: :width 100px
[[~/images/example.jpg]]
As per Jacobo's comment, add the following to your init.el file:
(setq org-image-actual-width nil)
Then in org-mode, you can use this for inline previews of JPGs and PNGs.
#+ATTR_ORG: :width 100
[[~/images/example.svg]]
and if you want to size this for both inline previews and html output:
#+ATTR_HTML: width="100px"
#+ATTR_ORG: :width 100
[[~/images/example.svg]]
#+ATTR_HTML: width="100px"
[[~/images/example.jpg]]
This is a sample on how to resize an image using percentages (Org mode version 9.0.5):
#+CAPTION: Weight space
#+ATTR_HTML: :alt neural network :title Neural network representation :align right
#+ATTR_HTML: :width 50% :height 50%
https://i.stack.imgur.com/nzHSl.jpg
Here is a way to resize images in emacs Org mode for preview (not exporting). Typically,
We want to set an image to a specific width like 249px when we need to.
We want to set a default image width, so that we don't need to specify +attr_html for every image - that would be tedious.
This can be achieved by configuring org-image-actual-width like follows:
(setq org-image-actual-width (list 550))
Then, in your .org file, if you have
#+attr_html :width 249
[[~/images/example1.jpg]]
then the image will be displayed in preview at width 249px. For another image, where no +attr_* is specified, the default width of 550px will be applied.
[[~/images/example2.jpg]]
You can see this behavior from the documentation in org-mode source code:
When set to a number in a list, try to get the width from any
#+ATTR.* keyword if it matches a width specification like
#+ATTR_HTML: :width 300px
and fall back on that number if none is found.
I found it hard to understand what does "a number in a list mean", so I looked at the implementation, and indeed, something like (list 550) works.
For LaTeX, to remove the default width=.9\linewidth, set the org-latex-image-default-width to empty string. By this way, the image will have its natural size.
To do that on the fly use the set-variable emacs command. Or to set this variable permanently, add the following line in your init.el :
(setq org-latex-image-default-width "")
Related
Does it add to the image if too small or crop if too big or just stretch the image to the desired size?
When you set interpolation=2, then you are using Bilinear interpolation, ti can be either used for upsampling or down sampling. In the case of upsampling you are doing something like
There are several types of upsampling and down-sampling, but bilinear one uses a combination of the neighbouring pixels to cimpute the new pixel.
Look to this links for more informations: link1; link2
Resize stretches the image to span the new size. It samples from the original image using the provided interpolation method.
I am trying to figure out whether it's possible to trim a PDFlib page AFTER its dimensions have been set.
For example, I have a non-standard page that is 500x10000pt:
$p->begin_page_ext(500, 10000, '');
...
$p->end_page_ext('');
After I'm done adding elements to it, I will know how tall that page should be.
How can I trim that page to the height of 2000pt?
How can I trim that page to the height of 2000pt?
by simple using:
$p->end_page_ext('width=500 height=2000');
It's just important that this will reduce the page dimension from the origin (lower left). Otherwiese you might use the cropBox Option to crop the page to some special area. For example:
$p->end_page_ext('cropbox={100 100 600 2100}');
Please see PDFlib 9.2 API Reference, chapter 3.3 for details for all option of end_page_ext().
Is there any way to resize the image and reduce it's weight in Angular/TS or in CSS? I mean something like 'picture' tag in HTML 5.1.
Resizing the image on the frontend won't change it's weight, as the full image has to be retrieved from the server anyways. The 'picture' tag isn't able to do this either.
The only thing coming close to what I believe you want to achieve is this Angular directive I found online:
https://github.com/oukan/angular-image-compress
This also only compresses on the client side and won't change the weight of the image retrieved in the first place.
I'm currently trying to find a way to embed external images (PNG) in my R markdown HTML output file in a scalable way.
What I have tried so far only sets them to a width equal to the space available in HTML file (don't know how much that is in pixels, maybe around 800px) even though the original image size is ~1500x700.
What I would like is that when I increase the window size of the HTML viewer that also the images increase, at least up to their original resolution. Down-scaling works without problems.
My attempts:
```{r fig.width=100, fig.height=55, echo=FALSE}
library(png)
library(grid)
img <- readPNG("images/image.png")
grid.raster(img)
```
and
<img src="images/image.png">
...without success.
Anybody got an idea how to do that? I would really appreciate your help :)
You may want to use out.width instead of fig.width and fig.height, with percentage, which will be percentage of the text area. You can use it with include_graphics(). If you do not set out.height, the ratio will stay ok.
```{r, echo=FALSE, out.width='80%'}
knitr::include_graphics("images/image.png")
```
I am adding a picture (some latex converted into a PNG using matplotlib) to my text using the following code:
par = doc.add_paragraph()
par.add_run().text = 'foo bar baz'
par.add_run().add_picture('pic.png')
par.add_run().text = 'blah blah blah'
This works OK, except that the picture pic.png is not vertically aligned in the rest of the text in the document:
I can get the alignment manually in MS Word by adding a character style with the advanced vertical alignment property set to "lowered by 10pt":
The problem is that I have no idea how to do this programatically using python-docx. Conceptually the steps would be to compute the size of the image, create a character style that was lowered by half that size minus half the size of the font and apply the style to the run containing the picture. How do you create a raised or lowered font style in python-docx?
For reference, here is pic.png:
Your image has a fairly large (transparent) border around it. I added a single pixel border inside its extents here to make it visible:
I expect Word is aligning the bottom of the image with the baseline (as expected). One approach would be to see if there was a way you could specify zero bottom border.
You could also try subscript on that image run. I'm not sure what it would do but it's worth a try. So something like this:
run = par.add_run()
run.add_picture('x.png')
run.font.subscript = True
If you find the run that you manually set to "lowered by 10pt", you can view the XML for it like this (aircode):
run = vertically_adjusted_run() # however you get ahold of it
print(run._element.xml)
I expect you'll see something like this:
<w:r>
<w:rPr>
<w:position w:val="20"/>
...
... where the w:position element sets the adjustment from the baseline. The value is specified in half-points.
Anyway, neither this adjustment nor even that low-level element are supported by python-docx yet, so you'd need to get in there with lxml calls to do the needful if you wanted it badly enough.