FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Syntax
(Moderators: fry, REAS)
   Loading image from URL question
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: Loading image from URL question  (Read 2462 times)
itpshiffman

WWW Email
Loading image from URL question
« on: Nov 11th, 2003, 12:47am »

Hello all -- i'm writing a little thing which loads an image from the net, i.e.:
 
b = loadImage("http://207.251.86.248/cctv26.jpg");
 
It works 100% a-ok within the proce55ing IDE, but once I publish it to an applet it's no good. .  I've done it w/ java before (and i had to do it differently than just loading a local file), but not with proce55ing. .   Anyone have any suggestions?
 
Thanks!
Dan
« Last Edit: Nov 11th, 2003, 12:49am by itpshiffman »  
arielm

WWW
Re: Loading image from URL question
« Reply #1 on: Nov 11th, 2003, 12:57am »

you can't directly load files that are not at the same "codebase" than your applet (unless it's a signed applet...)
 
one solution is to have the images located at the right places,
 
but if the goal is to have access to random images from the web, i think it's a matter of using a server-side script (php, cgi...) that will handle the redirection properly.
 
(can't help you with that one, but i think you can find some related posts in this forum, using the built-in search engine...)
 

Ariel Malka | www.chronotext.org
itpshiffman

WWW Email
Re: Loading image from URL question
« Reply #2 on: Nov 11th, 2003, 8:46pm »

Thanks for the response.  I used python to load an image (from a URL) and output it via a CGI in the applet's local directory -- works like a charm.  If anyone is interested, here's the code:
 
----------------------------
#!/usr/bin/python
 
import urllib
 
print "Content-Type: image/jpeg"
print
 
image = urllib.urlopen("PUT IMAGE URL HERE")
print image.read()
 
----------------------------
 
Assuming the CGI is named "IMG.cgi" and is stored in the applet's local directory, you can then simply say:
 
b = loadImage("IMG.cgi");
 
If you wanted to get really crazy, you could make the URLpath a parameter passed to the CGI. . .
 
Rock n' roll!
 
Dan
 
Jerronimo

WWW
Re: Loading image from URL question
« Reply #3 on: Nov 11th, 2003, 8:49pm »

It wasn't until i read this solution that I understood the problem.
 
Good to know though... I want to do a sketch that picks random photos i've taken and do something with them.
 
No idea what yet though...
 
but this is a piece of that puzzle that I'll be needing.
 
REAS


WWW
Re: Loading image from URL question
« Reply #4 on: Nov 13th, 2003, 8:34pm »

Hello Dan. Thank you for posting this.
 
bren

WWW Email
Re: Loading image from URL question
« Reply #5 on: Nov 28th, 2003, 4:18pm »

I did something similar in PHP for Flash thing I did that loaded in NYC webcam pictures: http://www.brendandawes.com/manhattan/
 
You need to have the GD Image Library installed with PHP but here's the script should anybody want it:
 
Code:

<?php
// parameters
// w = width of image
// h = height of image
// url = the url of the image
 
 
 
 
function LoadJPEG ($imgURL) {
 
$fp = fopen($imgURL, "rb");  
 
if($fp){  
while (!feof($fp))  
{  
$imageFile.= fread($fp, 1024);  
}  
}
fclose ($fp);
 
 
 
$tmpfname = tempnam ("/temp", "IMG");
 
$fp = fopen($tmpfname, "w");
fwrite($fp, $imageFile);
fclose($fp);
$width = $w;
$height = $h;
$im = imagecreate($width,$height);  
$image = ImageCreateFromJpeg($tmpfname);  
 
$imagedata = getimagesize($tmpfname);  
 
imagecopyresized ($im, $image, 0, 0, 0, 0, $width, $height, $imagedata[0], $imagedata[1]);  
 
 
Header("Content-type: image/jpeg");  
imagejpeg($im, '', 90);
 
 
 
   
   
##-- Delete Temporary File --##
unlink($tmpfname);
##-- Check for errors --##
if (!$im) {
print "Could not create JPEG image $imgURL";
}
return $im;
}
 
$imageData = LoadJPEG($url);
 
 
?>

 
Hope someone finds it useful.
 
Pages: 1 

« Previous topic | Next topic »