How do you convert a TIF image into PDF within coldfusion - coldfusion

The closest I have been able to get is using this code
<cfset Background = ImageNew("",1725,2625)>
<cfimage source="#APPLICATION.config.serverpath#/ad1.tif" name="ad1">
<cfset height1 = ImageGetHeight(ad1)>
<cfset width1 = ImageGetWidth(ad1)>
<cfset resImage1 = ImageCopy(ad1,0,0, width1, height1)>
<cfset ImagePaste(Background,resImage1,150,150)>
<cfdocument format="pdf" pagetype="custom" pagewidth="5.75" pageheight="8.75" fontembed="no" name="temp" margintop="0" marginbottom="0" marginleft="0" marginright="0">
<div style="position:absolute; top:0; left:0; right:0; bottom:0; z-index:0;width:100%;height:100%;">
<cfimage action="writeToBrowser" source="#Background#" style="width:1740px; height: 2650px;">
</cfdocument>
This gets me very close to the exact duplicate of my TIF image, but for some reason the image is reduced by like 5 pixels on the width, and I cannot figure out why.
A bit more details:
The ad1.tif image is 1425x1125, the final pdf document that gets produced is 1725x2625. As you can see I use 5.75 x 8.75 inches on the cfdocument. This translates in the PDF document being 300DPI. When I load up the PDF document in photoshop it does state the document is in 300DPI.
You might notice that the ImageNew uses 1725x2625 and the cfimage uses 1740x2625. If I matched the cfimage dimensions to the imagenew (which makes perfect sense), then you end up with having this white border on the top, right, and bottom. The image is still off by like 5 pixels on the width. So I am forced to make it a bit bigger to get rid of that white border. If I can just figure out why that image is 5 pixels off.

Well obviously your original question has been answered, but for the image resolution issue, you might try adding scale="100" to your cfdocument tag. That might prevent it scaling the image down (which is the same thing as lowering resolution). I'm not sure it will work, since I haven't tried it.
As a side note, I don't understand why people keep answering questions in the comments instead of in the answers.

Related

Change Y Axis in Image Chart

I am trying to create a Image chart - Line chart . I want my Y AXIS- from 6 to 9 . But I am not able to control the variable
<img src="https://image-charts.com/chart?cht=lc&chd=a:6.17,7.18,8.8|7.17,6.8,8.8&chs=600x600&chco=00FF00,0000FFFF&chyt=y&chyr=1,6.1,9.1|2,6.1,9.1" classed="displayed" alt="Graph: no internet connection."
align="center" />"
How to change the chyr parameter to control . IS my parameters wrong
Not very familiar with "image-charts", but, you can use this chart editor1 for configure your charts.
I modified the code - without really knowing the correct values to supply - as follows:
https://image-charts.com/chart?cht=lc&chd=a:9.17,7.18,8.8|7.17,6.8,8.8&chs=600x600&chco=00FF00,0000FFFF&chyt=y&chyr=1,6.1,9.1|2,6.1,9.1
I changed:
chd=a:6.17
For:
chd=a:9.17
The result is:
<img src="https://image-charts.com/chart?cht=lc&chd=a:9.17,7.18,8.8|7.17,6.8,8.8&chs=600x600&chco=00FF00,0000FFFF&chyt=y&chyr=1,6.1,9.1|2,6.1,9.1" classed="displayed" alt="Graph: no internet connection." align="center" />
In case this modification didn't work for you, please, check the documentation and test the chart editor.
1 Editor found at the documentation.

Add an image to Rmarkdown Bookdown output before top level heading

The example below (i.e. saved as a file index.rmd ) has the same code chunk to display an image above and below the top level heading, but the image doesn't appear above the top level heading. This occurs if there is a file _output.yml with only this entry bookdown::gitbook: in the same directory.
That line seems to enforce a table of contents (which I want) and that appears to strip out anything (image or text) before the first top level heading by default (which I don't want) - so can this behaviour be modified?
---
site: bookdown::bookdown_site
---
```{r echo=FALSE, message=FALSE, warning=FALSE}
library(imager)
im <- load.image(system.file('extdata/Leonardo_Birds.jpg',package='imager'))
plot(im, axes=FALSE)
```
# R Markdown
```{r echo=FALSE, message=FALSE, warning=FALSE}
library(imager)
im <- load.image(system.file('extdata/Leonardo_Birds.jpg',package='imager'))
plot(im, axes=FALSE)
```
What follows is workaround to your Options 2 and 3, using Markdown and CSS to style images and HTML+CSS to style text; also, using base64 image (transparent gif) generator as an space separator between elements.
Beware of whitespaces! (at the end of each line - place two white spaces and hit ENTER)
Does one of these approaches/hacks work for you? If not, it would be better to delete the answer, it may be misleading to others.
---
title: |
![](www/image.png){width=300px}|
|:-:|
![](www/image.png){width=300px style="display: block; margin:0 auto"}
![](www/image.png){width=300px height=90px align=left}
![](www/image.png){width=300px height=90px align=center}
![](www/image.png){width=300px height=90px align=right}
![](data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==){width=150px}
R Markdown Title
<center>R Markdown Title</center>
<p style="text-align: right;">R Markdown Title</p>
![](data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==){width=150px}
author: "Author Name"
date: "08/03/2020"
---
Using Markdown table to "style" images |-| (left-aligned), |:-:| (centered) and |-:| (right-aligned) will work well with simple RMarkdown outputs.
I realised that you have an image under # top level heading positioned at the very top of the page - with top:0px. causing image duplication and, possibly, hover problem:
<img src="https://i.imgur.com/GiViTbA.png" style="position:absolute;top:0px;height:100px;" />
replace with:
![](http://stackoverflow.com/favicon.ico){width=50px style="display: block; margin:0 auto;"}
and see what will happen.
---
title: |
![](https://i.imgur.com/GiViTbA.png){width=300px style="display: block; margin:0 auto;"}
![](data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==){width=50px}
R Markdown Title
![](data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==){width=50px}
output:
html_document: default
---
# I'm a top level heading {-}
![](http://stackoverflow.com/favicon.ico){width=50px style="display: block; margin:0 auto;"}
Note, you need to replace the image with a local image if you want to show the image in the rstudio viewer.
The image will be visible in the html file created when you knit, if you open in a browser connected to the internet.
```{r echo=FALSE, message=FALSE, warning=FALSE}
plot(cars)
```
EDIT:
Let's try to find a common ground, A Minimal Book Example, github here.
Adjustments made in index.Rmd:
---
title: |
![](data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==){height=300px}
author: "Author Name"
date: "`r Sys.Date()`"
site: bookdown::bookdown_site
output: bookdown::gitbook
---
# Prerequisites
<img src="https://i.imgur.com/GiViTbA.png" style="position:absolute;top:50px;height:300px;align:center;" />
This is a _sample_ book written in **Markdown**. You can use anything that Pandoc's Markdown supports, e.g., a math equation $a^2 + b^2 = c^2$.
index.Rmd output:
Adjustments made in Chapter: Introduction (01-intro.Rmd):
# Introduction {#intro}
![](data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==){height=240px}
<img src="https://i.imgur.com/GiViTbA.png" style="position:absolute;top:50px;height:300px;align:center;" />
You can label chapter and section titles using `{#label}` after them, e.g., we can reference Chapter \#ref(intro). If you do not manually label them, there will be automatic labels anyway, e.g., Chapter \#ref(methods).
01-intro.Rmd output:
With this solution we are "masking" a top level heading (# Introduction) with .png image, which will appear in the Table of Content as text.
Disadvantage: besides the obvious hack, image width must be at least equal or wider than top level heading title.
Note: 3 options are provided here, and none of them are perfect. The perfect solution may rely on modifications to the bookdown package?
Option 1:
Use includes with before_body like this in your _output.yml file (suggested here):
bookdown::gitbook:
css: assets/style.css
includes:
before_body: assets/big-image.html
after_body: assets/footer.html
Disadvantages:
i) Requires making a html file just to insert an image.
ii) If using a web-based image, won't show in Rstudio viewer.
iii) If using a local image, path can get mixed up and won't show in online web html rendering
iv) Includes image at the top of each chapter of bookdown if using before_body: my_image.html. Alternative option in_header: my_image.html does not seem compatible with the sidebar index.
Option 2
Insert image via yaml in index.rmd, using the solution under Tip 3 Add a Logo in your title/header/footer at this blog post
---
title: |
![](my_image.png)
My title
Disadvantages:
i) When you hover over the image, it displays a copy of the image in a slightly different location (Can this "Hover" behaviour be disabled?)
ii) If using a web-based image, won't show in Rstudio viewer.
iii) If using a local image, path can get mixed up and won't show in online web html rendering
Option 3
The code below borrowed from here (which you can place below the top level heading) presumably goes direct through the knitting process and inserts itself in the final html. The issue is that the image doesn't make room for itself and ends up over the first text. Is there some simple html/css to sort this out?
<img src="https://i.imgur.com/GiViTbA.png" style="position:absolute;top:0px;height:100px;" />
Disadvantages:
i) Image doesn't make room for itself and ends up over the first text. You can get around this with a hack by coding extra space (trial and error) through the yaml title like this:
title: |
.
.
.
.
site: bookdown::bookdown_site
EDIT
This is superseded by Radovan's accepted answer.
This was the best answer, taking option 3 from my previous answer, and combining a code approach to making the relevant space from Radovan's answer.
You will still have problems if you want to include a title in the YAML (I don't need this, as my title is in the image).
Also, on first loading the page, it presents nicely, but image is not seen if you go to the top of the document using the table of contents (the inheader approach used by this bookdown shows a better behaviour, but appears at the top of every chapter, which is not desired).
---
title: |
![](data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==){height=300px}
output:
html_document: default
---
# I'm a top level heading {-}
<img src="https://i.imgur.com/GiViTbA.png" style="position:absolute;top:50px;height:300px;align:center;" />
Note, you need to replace the image with a local image if you want to show the image in the rstudio viewer.
The image will be visible in the html file created when you knit, if you open in a browser connected to the internet.
```{r echo=FALSE, message=FALSE, warning=FALSE}
plot(cars)
```
The problem of hovering the image duplicating the image can be fixed by removing the line below from the css file that is generated at \libs\gitbook-2.6.7\css\style.css
.book .book-header h1 a:hover{color:inherit;text-decoration:none}#media (max-width:1000px){.book .book-header h1{display:none}}
as a result, this code below places the image right above the title:
---
title: |
![class='btn noHover'](images/Stats.png){width=400px style="display: block; margin:0 auto; align:center;" }
<center>GEOG380 Basic Stats with R</center>
---

Gradient color Raphael

When in Raphael I set color to 90-#7ADADD-#338A93 on path it becomes gradient. Then when I inspect element I can see it's fill property is set to something like: url(#490-_7ADADD-_338A93).
If I try to change it to 90-#7ADADD-#338A93 it becomes black.
The question is how to change gradient color externally? How can I calculate this url(#490-_7ADADD-_338A93) from my original 90-#7ADADD-#338A93?
If you look at the full SVG source it might look something like this
<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
<defs>
<linearGradient id="490-_7ADADD-_338A93" x1="0%" y1="0%" x2="100%" y2="0%">
....
</linearGradient>
</defs>
<ellipse cx="200" cy="70" rx="85" ry="55" fill="url(#490-_7ADADD-_338A93)" />
</svg>
The url(...) part is actually a reference to a gradient defined in defs. If you change the reference to something that doesn't exist it will be displayed with a black fill.
The logical thing to do in Raphael is keep your gradient manipulation within the library. If you do...
path.attr({"fill": "90-#fff-#000"})
path.attr({"fill": "90-#ccc-#666"})
Then Raphael will insert a new linearGradient and reference it for you.
If you really need to manipulate the SVG source then you can do something like...
var gradient = document.getElementById('490-_7ADADD-_338A93');
var stops = gradient.querySelectorAll('stop');
stops[0].setAttribute("stop-color", "#c00");
stops[1].setAttribute("stop-color", "#00c");
But this will break VML compatibility (IE 8 or less).

How do I display a large image when rolling over a thumbnail that allows text to be written over the large image

I have images in a table and want to click on each and have them enlarged on the screen. I can find alot of these snippets online but none I have found allow for writing text over the enlarged images. These pix are artwork and need a copywrite statement on top of them when enlarged. Anyone know either how to do this or where to find it online....thx....David
The only way I can find to add text over an image is to create the image as the background. Setting up a division and table allowed me to only have the background apply to a certain area of the screen.
You can try this code :
<div id="lare_img">
<div class="copyright">Your copy right text here </div><div class="img_file"><img src="img_01.jpg"></div></div>
and style CSS :
<style>
#lare_img{
width:100% // change to your image large width ;
height:100% // change to your image large height;
position:absolute;
}
.copyright{
position:absolute;
bottom:20px;
left:20px;
z-index:999;
}
.img_file{
width:100%;
height:100%;
float:left;
}
</style>

Extract all Images from HTML whose width or height higher than a specified value - Regex

I'm trying to make a small link share function with Classic ASP like LinkedIn or Facebook.
What I need to do is to get HTML of remote URL and extract all the images whose width are greater than 50px for example.
I can crawl and take the HTML and also I can find the images with this regex:
<img([^<>+]*)>
It matches; <img src="/images/icon.jpg" width="60" height="90" style="display:none"/>
Then I'm able to extract the path but sometimes it matches <img src="/track.php" style="display:none" width="1" height="1"/> which is not a real image.
Anyway, I feel like you are gonna be mad because of classic ASP but my company ....
I know there are lots of topics about this issue and mostly, they recommend not to USE regex but I couldn't find a way to this with classic asp. Is there a component or something to this?
Regards
This will get you close:
<img [^>]*width="(0?[1-9]\d{2,}|[5-9]\d)"[^>]*>
It accepts image tags with a width of 50 or greater.
Edit: tags with unspecified widths:
<img [^>]*width="(0?[1-9]\d{2,}|[5-9]\d)"[^>]*>|<img ((?!width=)[^>])*>