Provide url and store image from the url in a file in file system in groovy - image

I am doing a project in grails using groovy to upload an image. I have been able to fetch a file from my-computer and store it in a location and display it from there. I wish to accept a url from the user during run time and store the image in the locaion and display from there. Help please

Please consider Gregg's comment, but if you stay with your idea, this is the way I would do it:
new File("path/to/local/image.jpg").bytes = new java.net.Url("http://url.from.user/image.jpg").bytes

Related

how to get image Details form mobile folder location

We have image path like
cdvfile://localhost/persistent/DCIM/Camera/1395167011485.jpg.
OR
file://localhost/persistent/DCIM/Camera/1395167011485.jpg.
We need get image details using this path.Image details like Image Name,height, width.We are developing Cordova mobile apps.Please guide to us .Which plugin we need use for Details.
You don't need a specific plugin, though you could use file transfer to help with it. Something like the following will work fine:
var image = document.createElement('img');
image.src = "img/My_Image.png";
console.log(image.height);
console.log(image.width);
You might find this javascript exif library useful.

PHPExcel Load image from outside URL

Does anyone know how to make setPath() method able to load an image from outside server? Because all images is store on other server.I don't have any idea how to do that. Please help me. thanks
<pre>
$objDrawing = new PHPExcel_Worksheet_Drawing();
$objDrawing->setPath('http://domain.com/images/testing.jpg');
$objDrawing->setHeight(96);
$objDrawing->setOffsetX(27);
$objDrawing->setOffsetY(40);
$objDrawing->setCoordinates('A9');
$objDrawing->setWorksheet($this->excel->getActiveSheet());
</pre>
Images can't be referenced from a URL, you need the image in your local filesystem because PHPExcel needs to extract information from that image. Use curl (or even file_get_contents()) to pull the image to the local filesystem first. Once the image has been embedded in the Excel document, you can delete the file again.
You can put false as the second option in the setPath() method. Tcpdf gets the image from the URL and PHPExcel doesn't throw an exception.

Can you use a URL to embed an image inline in MVCMailer

In looking at the MVCMailer step by step, I see that you can embed images inline using cid in the HTML.
https://github.com/smsohan/MvcMailer/wiki/MvcMailer-Step-by-Step-Guide
I see the code that talks about embedding:
#Html.InlineImage("logo", "Company Logo")
var resources = new Dictionary<string, string>();
resources["logo"] = logoPath;
PopulateBody(mailMessage, "WelcomeMessage", resources);
My question is rather than use a path within the site like:
resources["logo"] = Server.MapPath("~/Content/images/logo.png");
Can I somehow get at images I have in the Azure Cloud or S3 Cloud where I have plenty of space?
Please let me know if there is a way to get the image from some other source than the server the MVC mailer is running on.
Thanks,
Victor
In Server.MapPath(my_path), my_path, specifies the relative or virtual path to map to a physical directory. Server.MapPath is related with local FileSystemObject so in that case it will look for the file (you pass as parameter) in a location within local web server. More info is described here:
http://msdn.microsoft.com/en-us/library/ms524632(v=VS.90).aspx
So if you image is located at http://azure_storage_name.blob.core.windows.net/your_public_container/image_name.jpg, the passing it to Server.MapPath() will not work as this is not a location in local file system. I tried and found that it will not accept and I also try to tweak a few way but no success. IF you can change the code behind and which can access the resources from a URL then it will work otherwise not.

How to check that Image is already exist or not on given path in GWT + MVP4G

I want to check if the Image exists or not on the fileSystem. I am using GWT 2.4 with the MVP4G framework. When I use IO.File on the client side to check file.exist(), it gives me an error because we cant use IO on client side, so How can I check this..?
How did you get the image?
The only way you should get the image is by using some file upload mechanism and any one of those will only let the user choose an already existing file; so there is actually no need to check for the file existence.
For file upload you can use the gwt library gwtupload. or use apache File Upload library.

iText Add Image to PDF in a web application

I'm posting this for a friend. He is not able to access Stackoverflow from work (Third Party Cookies Appear To Be Disabled) :)
Ok here goes:
They have a Web application (JSP/Servlets/Custom Framework) and he is trying to generate a PDF on the fly. Now he wants to add images to that PDF. But it ain't working. Here is the piece of code:
Image image = Image.getInstance("../graphics/caution_sign.gif");
The graphics folder is on the parent project (webcontent/graphics/) and this is how they access the images from that folder in all other places (in the JSPs).
Now I read on another post that we need to use the real absolute path to access the Images. But the problem here is this is a POJO and there is no access to the servletContext in this class.
The PDF is generated fine, but the Image does not show and the error is:
C:\Program Files\IBM\SDP\runtimes\base_v7\profiles\was70profile1\..\graphics\caution_sign.gif (The system cannot find the path specified.)
It is trying to look for the "Graphics" folder in a different location instead of looking within the webcontent folder.
Hope my question is clear and would appreciate a lot if someone can help with this and help in resolving this issue
Thanks so much
Harish
He was able to solve it using this piece of code. Hope this helps someone else.
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
String path = classLoader.getResource("/graphics/caution_sign.gif").getPath();
Image image = Image.getInstance(path);
Thanks
Harish
Following code can be used to access image path inside a java class.
URL imageUrl = getClass().getProtectionDomain().getCodeSource().getLocation();
Image img=Image.getInstance(imageurl+"../../../some/images/pic.gif");
Small change from the previous solutions :
Step1: Below code will return the class path including class file name
URL classURL = getClass().getProtectionDomain().getCodeSource().getLocation();
Step2: Get the base path by removing class name
String basePath = classURL.getPath().replaceAll("<classname>.class","");
Step3: Navigate to the image location based on your project
Image headerLogo = Image.getInstance(basePath+"../../../../../../../images/header_logo.gif");

Resources