Trying to use image from URL with Kohana Image class - image

I'm trying to use an image from a URL with Kohana image class. http://kohanaframework.org/3.0/guide/api/Image
Is this possible or does the image always have to be local to the project?
I'm accessing the image like this:
http://www.mysite.com/temp/myimage.jpg
from the same site.
However the temp folder in the above URL is actually an Alias in Apache so is outside of the document root.
Can anyone shed any light on a solution?
The kohana image library says its not an image because it either fails
realpath($file);
or
getimagesize($file);
Cheers.

The image does have to be local to the project.
What you can do is grab a copy off the remote and save it to your project and serve that.
$offsite_path = 'http://example.com/images/steve-buscemi.jpg';
$local_copy = Remote::get($offsite_path);
$local_path = 'images/steve-buscemi.jpg';
file_put_contents($local_path, $local_copy);
echo HTML::image($local_path);
There is a feature request to allow for remote image access using the Image module.

Related

Meteor , read an image stored on server outside public folder

i can't resolve image file's path on my server from my meteor app to use it as a source of my image tag , also i don't want to put it in public folder as it refreshes due to meteor watching with every image upload.
For this you can use Meteor-files. This packages allow you to insert file in your database. also you can work another thing with this packages

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.

Unable to access the image from src/images folder

I have created images folder under src in Netbeans..to get image using following code in my application.
URL url = ClassLoader.getSystemClassLoader().getResource("/images/file.jpg");
logoimg=new ImageIcon(url);
but it is not loading any image..I have tried many of existed solutions in web, but no use.
My requirement is need to run my application jar in any system without missing images.
following code fixed my probelm
ImageIcon ImageIcon = new ImageIcon(getClass().getResource("/images/logo.png"));

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.

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