Add an image acting as a link toward it's own location - html

Using rmarkdown and the include_graphics function from knitr I would like to be able to do something like:
<img src="image.png" alt="image" width="30%">
Where I can see a small version of an image and click on it to see its full size original version. I am sure there is an easy way to wrap something like:
```{r ,out.width="30%"}
knitr::include_graphics('image.png')
```
within an html link but I can't find how.
What I like with knitr::include_graphics() is that
it's in a chunk so I can generate the image's names with R
it copies images to the final folder where I want my Rmardown code to be compiled.
An example of what I would like to do but I don't how nor if it's possible:
```{r ,out.width="30%"}
images=paste0('image',1:3,'.png')
for( i in images){
#open <a href = i>
knitr::include_graphics(i)
#close </a>
}
```
Should do something like:
<img src="image1.png" alt="image" width="30%">
<img src="image2.png" alt="image" width="30%">
<img src="image3.png" alt="image" width="30%">

You can use the chunk option fig.link, e.g.,
```{r, out.width="30%", fig.link='image.png'}
knitr::include_graphics('image.png')
```
```{r}
images = paste0('image', 1:3, '.png')
```
```{r, out.width="30%", fig.link=images}
knitr::include_graphics(images)
```

you can simply do:
<a href = "./image.png">
```{r, out.width="30%"}
knitr::include_graphics('./image.png')
```
</a>
For me, this works.

adding on top of what Jrm_FRL said, just incase you ment the link takes you where the link is originally from I added this code, had to shorten the link with stackoverflow and imgur, let me know if you have issues.
---
title: "picture_as_link"
author: "stackoverfl"
date: "5/27/2020"
output: html_document
---
<a href = "https://en.wikipedia.org/wiki/Lake_of_the_Ozarks">
```{r, out.width="30%"}
knitr::include_graphics('https://i.stack.imgur.com/JRy36.jpg')
```
</a>

Related

How to arrange hyperlinked images in Rmarkdown?

I'm trying to make a little HTML file using Rmarkdown. I'm using HTML to set the images into the blocks.
Here is what I currently have.
But my desired goal is do something like this. Where I have two images per block.
I'm not sure if HTML is the best way to do this but I am open to using knitr
Here is my code
---
title: "Landing Page"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
runtime: shiny
---
```{r setup, include=FALSE}
library(flexdashboard)
library(shiny)
```
<div style="text-align:center;">
<div style="display:inline-block;">
<div class="wp-block-image" style="display:inline-block;">
<center>
<figure class="aligncenter size-full">
<a href="https://www.idashboards.com/wp-content/uploads/2020/06/IT-Service-Desk.png" target="_blank" rel="noopener">
<img loading="lazy" width="517" height="261" src="https://www.idashboards.com/wp-content/uploads/2020/06/IT-Service-Desk.png" alt="" class="wp-image-5379">
</a>
<br>
<figcaption>
<b><u><font size="+2">
Dashboard Example 1
</font size>
</b></u>
</figcaption>
</figure>
</center>
</div>
</div>
Adopted from this answer, you can put images in a kable:
---
title: "Fun with flags"
output: html_document
---
```{r results='asis'}
image_stringer = function(abbr){
sprintf('![](http://flagpedia.net/data/flags/mini/%s.png)', abbr)
}
dat <- data.frame(
col1 = c(image_stringer('nl'), image_stringer('de')),
col2 = c(image_stringer('ch'), image_stringer('be'))
)
library(knitr)
kable(dat, col.names=NULL)
```
Alternatively, you can put your image in a <table> format (for an example, just inspect the output of the kable block), which gives wider control over formatting.

Replacing ALL HREF URL attributes with ALT tag and Placeholder Text

I need to find an automated way to update href URLs in a HTML file with the corresponding image alt text the anchor tag is wrapping while also including leading and closing RPL text.
Start:
<img src="/images/image.jpg" alt="ALT_TEXT">
End:
<img src="/images/image.jpg" alt="ALT_TEXT">
Breaking down the new URL:
First Variable: ${clickthrough('<br>
Second Variable: ALT_TEXT<br>
Third Variable: ')}
Anyone know where I should start in designing a solution for this problem? What coding language might handle this?
The language that you are looking for is JavaScript.
Here is a working example that does what you mentioned. (and here is a codepen with the same example)
const anchorElements = document.querySelectorAll('a');
[...anchorElements].forEach((anchor) => {
const altText = anchor.querySelector('img').alt;
anchor.href = "${clickthrough('" + altText + "')}";
})
<img src="https://place-hold.it/300x100" alt="text1">
<img src="https://place-hold.it/300x100" alt="text2">
<img src="https://place-hold.it/300x100" alt="text3">

Elixir - How to embed an image into an html , on email

I am trying to embed an image to html when sending email.
I have the image (logo.png) and html (welcome.html.eex) located under priv
Sadly, I receive the email without the image in it.
here is the email I receive:
when I inspect element I get: (no src=" ... ")
<img width="212px" height="26px" align="bottom">
though - when I preview locally my html (from my-html.html - see in my code ) seems ok:
here is my welcome.html.eex
<p>
<span>
<strong>Bem-Vindo hii</strong> à
<img
src="<%= ~s(data:image/png;base64,) <> Base.encode64(File.read! (Path.join("#{:code.priv_dir(:my_app)}", "logo.png"))) %>"
width="212px" height="26px" align="bottom"/>
</span>
</p>
here is my code, sending email adding the html using bamboo:
import Bamboo.Email
def send_verify_email() do
File.write "my-html.html", get_html() # writing the html localy - to verify..
new_email()
|> to("foo#bar.com")
|> from(#from_addr)
|> subject("Welcome")
|> html_body(get_html())
|> Mailer.deliver_later
end
end
def get_html() do
EEx.eval_file(Path.join("#{:code.priv_dir(:my_app)}", "welcome.html.eex"), [tok: "123"])
end
what am I doing wrong?
how can I attach a base 64 image on email html?
edit
I also tried adding image by path
welcome.html.eex
<img src="<%= Path.join("#{:code.priv_dir(:my_app)}", "logo.png") %>"
but still get same results - locally html seems ok, but on email html is:
when I inspect I get
<img src="https://ci4.googleusercontent.com/proxy/4eMU8Te6MM215JLJ5gm3Z9jnC4hytOkDeF4ldFGb1pC17GDhtZphCtH623p1ZwNYZxBfAatQtlX_V9MKALbOE0jIzxVXJ43tZLeA5hUT7tjs7FEz3_PVoUQ5Ih7w0rvuRtLy7pVqR9UoU5TBF5E=s0-d-e1-ft#http:///home/dina/Documents/WK/my_umbrela_app/_build/dev/lib/my_app/priv/logo.png" width="212px" height="26px" align="bottom" class="CToWUd">
so I do have src="" but it seems broken.. :(

Add a link to a image

How do I add a link to the image? I am unsure what code to use.
<?php
$company_image = '';
$company_description = '';
if (!empty($options['company_photo'])){
$company_image = $options['company_photo'];
}
else {
$company_image = 'https://nemo-uploads-clone.s3.amazonaws.com/uploads/homeabout/image/1/philly.jpg';
}
you can't straightly add a link to the image variable which is defined,
but you can add the link like this:
in html you can use this:
<a href="https://www.something.com">
<img src="img.jpg">
</a>
in php, you can use "html tags" inside of ".php" file like this:
echo ' <img src="img.jpg"/> ';
the code above, will show an image on the screen that refers to wikipedia link!
The HTML for an image with a link
<a href="https://www.example.com">
<img src="https://www.example.com/img.png">
</a>

html image not appearing

I have the following line of code:
<IMG SRC= "Home.png">
I copied this directly from a different part of my code that worked. However, now the home image won't show up on my site. It says it prints it, but it's not visible. What's going on?
edit:
if(isset($_SESSION['userInfo']['username'])){
echo '<div class = "header"><IMG SRC= "Home.png" ALT="image">
<IMG SRC= "ViewProfile.png" ALT="image"> <IMG SRC= "ViewCart.png" ALT="image">';
echo '</div>';
else{
echo '<div class = "header">
<IMG SRC= "Home.png">
<IMG SRC= "FAQ.png"></div>';
}
You are missing the closing parenthesis } for the if statement. That might be the problem.
Try this...
if(isset($_SESSION['userInfo']['username'])){
echo '<div class = "header"><IMG SRC= "Home.png" ALT="image">
<IMG SRC= "ViewProfile.png" ALT="image"> <IMG SRC= "ViewCart.png" ALT="image">';
echo '</div>';
} else {
echo '<div class = "header">
<IMG SRC= "Home.png">
<IMG SRC= "FAQ.png"></div>';
}
Try
<div class="header">
<img src="Home.png"/>
<img src="FAQ.png"/>
</div>
Is it a broken image icon on the browser?
One thing might be that Home.png is in another directory. Did you copy this code from the same file or another file (possibly located in another directory)? If you copied this code from a file located in another directory you will need to format the image source link accordingly.
For example say you have a directory structure like so:
-index.htm (File)
-Home.png (File)
-js (Directory)
-css (Directory)
-pages (Directory)
---example.htm (File inside Pages directory)
If you then copied the code from your index.htm file to the example.htm located in your pages directory you would need to modify the link in the example.htm page like so:
<img src="../Home.png" />
Note the ".." which tells the browser to look in one directory up from where your html page is located.
be sure that the image and file in the same folder
and be sure that the name of image Home with H as capital letter