Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

get image from http and resize

Status
Not open for further replies.

Streetdaddy

Programmer
Jun 10, 1999
161
AU
anyone know a good article or tutorial about how to get an image from a url and resize? i have found a lot of complicated stuff but no simple implementations of it to help me get started :) Miles

Those Micros~1 guys sure know what they doing!
 
you can use the function getimagesize


$size=getimagesize("
then

calculate new sizes and use it in the tag img Anikin
Hugo Alexandre Dias
Web-Programmer
anikin_jedi@hotmail.com
 
thanks, i should have been more descriptive :(

I want to download the image, store on server, and resize to thumbnail. at regular intervals Miles

Those Micros~1 guys sure know what they doing!
 
so

$fpin=fopen("$image=fread($fpin,filesize("fclose($fpin);

$fpout=fopen("images/file.jpg","w");
fwrite($fpout,$image,strlen($image));
fclose($fpout);

then you can get the image size with getimagesize function.
Anikin
Hugo Alexandre Dias
Web-Programmer
anikin_jedi@hotmail.com
 
Hi.. don't know a lot about PHP, but I do know my Perl & Web Programming in general.

What you propose is not really resizing the image... to do this, you need to manipulate the bits of the image.

If you do it your way, always the whole image will be transferred, this is not an option with a page of thumbnails.

there should be a module available to deal with JPEG images.. if not, you are out of luck.

cu
trACE666
 
there's a module here. Karver provided the solution some time ago. It's a way to show thumnails in the fly.

My solution only provided the way to handle the copy of the file, not the showing.
Anikin
Hugo Alexandre Dias
Web-Programmer
anikin_jedi@hotmail.com
 
The solution required the GD image library to be installed, not sure if its available for windoze but I use redhat.

the code is:
-------------------image.php----------------------------
<?php
$src_img = ImageCreateFromJPEG($file_name);

/* desired width of the thumbnail */
$picsize = 100;

/* grabs the height and width */
$new_w = imagesx($src_img);
$new_h = imagesy($src_img);

/* calculates aspect ratio */
$aspect_ratio = $new_h / $new_w;

/* sets new size */
$new_w = $picsize;
$new_h = abs($new_w * $aspect_ratio);
//$new_h = 120;
/* creates new image of that size */
$dst_img = ImageCreate($new_w,$new_h);

/* copies resized portion of original image into new image */
imagecopyresized($dst_img,$src_img,0,0,0,0,$new_w,$new_h,imagesx($src_img),imagesy($src_img));

imageJPEG($dst_img);
ImageDestroy($dst_img);
?>
------------------------------------------------------------

from your main page to create a link to the main image but see the thumbnail displayed use this:
<a href=$file_name><img src=\&quot;image.php?file_name=$file_name\&quot; border=0>

get a copy of the gallery files from see if the code will help you.

By the way no java = no navigation on the site at the moment and it prolly looks alot crap in nutscrape and mozilla. ______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
thanks, ill go down the GD path and see what happens! thanks for the help :) Miles

Those Micros~1 guys sure know what they doing!
 
Karver i tryed it in windows :) Anikin
Hugo Alexandre Dias
Web-Programmer
anikin_jedi@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top