I wanted to place a google static map in a pdffile generated by using the fpdf extension.
and used code to make a tempfile first. Using this code. However I run into an error ('can't open image file').
// define the mapurl
$fullURL = 'http://maps.googleapis.com/maps/api/staticmap?center=Amsterdam&z=14&size=100x100&sensor=false';
// create a tempfile
$tempF = tmpfile();
fwrite($tempF, file_get_contents($fullURL));
//Rewind to the start of file
rewind($tempF);
// place the image in the pdf.
if (!empty($tempF)) {
$this->Image($tempF,$start_x, $this->GetY(),0,100);
}
fclose($tempF); // remove the tempfile
Note: OP's own answer extracted from the question.
Then I found out it can be done much easier... I don't need to use a tempfile. If I put the url in the image variable and give a format the thing works in two lines.. I don't use the height and width parameters in fpdf because they stretch the image into a unreadable form.
$fullURL = "http://maps.googleapis.com/maps/api/staticmap?center=". \
$row-Google_coor."&zoom=10&size=2200x200\
&markers=color:blue%7Clabel:D%7C".$row->Google_coor;
$this->Image($fullURL,$start_x, $this->GetY(),0,0,"PNG");
Saddly when using this function sometimes the program returns an error. The image could not be found. But when I put the url string in the browser the image shows up fine. Hopefully this is also a minor fallback.
Lets see if I find a solution on the google apis site https://developers.google.com/maps/documentation/staticmaps/?csw=1
For what it is worth I had this problem as well, I found that my server had an outgoing connections manager, this would automatically block the request, I had to add the ip, once this was done it worked fine.
I had a problem similiar to the OP's. I was getting an error when using FPDF and trying to get the static map image from Google Maps and into my PDF. I was getting "FPDF error: Missing or incorrect image file". What I did is to register in the Google Developer Console and get an API Key, just like they say in the documentation
Hope this helps.
You can download the image and use it with fpdf
$url ="https://maps.googleapis.com/maps/api/staticmap?center=Brooklyn+Bridge,New+York,NY&zoom=13&size=600x300&maptype=roadmap&markers=color:blue%7Clabel:S%7C40.702147,-74.015794&markers=color:green%7Clabel:G%7C40.711614,-74.012318&markers=color:red%7Clabel:C%7C40.718217,-73.998284&key=".$googleApiKey;
$img = __DIR__.'/img/map.png';
file_put_contents($img, file_get_contents($url));
$pdf->Image($img,null,null,170);
Hope that this will be helpful
Related
I'm using the latest version of the here javascript sdk 3.1.32.0
When I use H.service.Url.MultiValueQueryParameter for my via points like
{
...,
via: new H.service.Url.MultiValueQueryParameter(['50.1234,8.7654', '51.2234,9.1123']);
}
I see in the URL params of my request this: &via=%5Bobject%20Object%5D
Someone an idea why this happens?
Thanks in advance!
When you use "via" parameter, you define a list of via waypoints. A via waypoint is not a native datatype recongnized by JavaScript, therefore, you will see in the URL params the word object refering to a particular data structure, in this case the via Waypoint composed mainly by Latitude, Longitude.
Regards.
This took a while to figure out the actual issue with the malformed url params. I was dynamically loading the here maps service script on mount of a component. Accidentally this happened in some cases twice. In both cases H was globally available and everything worked like expected. BUT when the script was loaded twice H.service.Url.MultiValueQueryParameter didn't return the correct params. It basically encoded them twice, or tried to.
The other side issue was that https://www.npmjs.com/package/#types/heremaps is outdated and doesn't cover MultiValueQueryParameter. So I had to remove the types and use my own. Else I probably would have realized the issue earlier.
I am trying to extract thumbnails from source jpegs and save them to the file system, using the C# ImageSharp library. I see there is some mention of it in the intellisense for the component:
SixLabors.ImageSharp.Image.Metadata.ExifProfile.CreateThumbnail()
...but I can't seem to find any documentation for it or examples to call it correctly.
I did find this:
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
//method code:
Image<TPixel> thumbnail = image.Metadata.ExifProfile.CreateThumbnail<TPixel>();
https://docs.sixlabors.com/api/ImageSharp/SixLabors.ImageSharp.Metadata.Profiles.Exif.ExifProfile.html
...but I need to find where the TPixel type is to get it to work. VisualStudio doesn't recognize it and I can't seem to find a namespace or use it correctly:
"The type or namespace name 'TPixel' could not be found (are you missing a using directive or an assembly reference?)"
Legacy Windows .NET Framework could do this for System.Drawing.Image.Image.GetThumbnailImage() and it worked pretty well.
EDIT: Using tocsoft's answer, I changed the code to:
if (image.Metadata.ExifProfile != null)
{
Image<Rgba32> thumbnail = image.Metadata.ExifProfile.CreateThumbnail<Rgba32>();
thumbnail.Save(thumbnailPath, encoder);
}
...however, the image.Metadata.ExifProfile is null, which is unexpected since I know these source images have EXIF data.
EDIT: Actually, it's working now. Success! Thank you!
TPixel would be any of the pixel formats in the SixLabors.ImageSharp.PixelFormats namespace. But unless you are planning on interoperating with other systems that require the pixel data layed out in memory in specific ways you will likely just want to use Rgba32
Image<Rgba32> thumbnail = image.Metadata.ExifProfile.CreateThumbnail<Rgba32>();
I can get basic html text to flip 180*, but I'd like to know how to get a whole Doc in my Drive file to flip using a standalone script (so I can do it repeatedly). I'm aware I can get a doc, open the scripts editor and then use my flippin' project to flip the doc I called, but I don't know what the syntax looks like. My first flippin' success was pasting text into the .html file as simply as possible and using:
function doGet() {
return HtmlService.createHtmlOutputFromFile('Page');
getContent()
}
I just test ran it from the dialog box as a web app. But I'm interested in building this one command feature out into several different domains to get experience with the variety of possibilities available in GAS. Anyone care to tutor me? Please?!...
I embedded a Shiny application with an iframe in my website, and I am now trying to protect my Shiny application : I want the iframe to be reachable only in my website, not directly with its URL.
<iframe name="rshiny"
src="http://url-of-my-shiny-app/" style="border: none; width: 100%;height:800px;">
</iframe>
To do that, I am trying to get the URL of the parent which contains the iframe inside of my Shiny-app, and block it whether it's not the good website.
The problem is : I found how to get the URL parent in many languages but R. Does anyone know how I could do it ?
I had another possible solution, which doesn't work for the moment :
postForm('http://url.php', .params = params, curl = curl, style="POST")
I thought I could send a post variable from my website to my R application, like a key, to give the access only to the websites who know the key.
But I can't make it work.
EDIT : I think this question is different from the link suggested in the comments. Indeed, the suggested option doesn't seem to be usable in R Shiny.
I found a solution !
Over here, you can find a way to get the "GET" variables in your shiny app.
https://github.com/brianbolt/rShinyApps/tree/master/getParameters.shiny .
In my PHP code, I calculate a md5 password, which depends on the date, to make it change everyday, and I use it as a GET parameter in my iframe :
<iframe name="rshiny"
src="youradress?bins=<?php echo $md5password;?">
</iframe>
From that point, I can use it directly inside of my code (see input$n_breaks in the code I shared).
I create a reactive function in my server.R, which calculates the same md5 password.
In the end, we compare it to the password given in the parameters. If it's the same, we open the plots, read the data... Otherwise, we just stop the process.
I used something like
Dim i As String
i = Server.MapPath("~/photos/") + fileName
Only once in a project that was working and online, on the offline version, when I run it on my machine, its working, no errors, I uploaded it, it gave me an error like:
'~/photos/http://www.MyURL.com/photos/4411568359267Pic003.jpg' is not a valid virtual path.
Indicating a line in my code:
var marker = new GMarker(new GLatLng(<%=coordinates%>));
This have never happened before, and I don't know where to start troubleshooting as this script -Google Maps- doesn't even need images, i tried to comment it out, it gave me the same error but on a different script this time, the one that show formatting toolbar for the text areas
Line 8: new nicEditor({buttonList : ['fontSize','fontFamily','fontFormat','bold','italic','underline','strikethrough','forecolor','bgcolor','removeformat'], iconsPath : '../nicEdit/nicEditorIcons.gif'}).panelInstance('<%= txtDescription.ClientID %>');
..please HELP :'(
can you post your fileupload aspx page and your function so we can troubleshoot it.
"'~/photos/http://www.MyURL.com/photos/4411568359267Pic003.jpg'"
look closely at the url, it is tacking the full url on to "i". what type of control or you using, a generic or a server side control
solved, turns out the error is due to old database records when i was storing the whole path in the fileName...Thanks Joshua and Keltex