Jump to content


Photo

Resizing an image (by GD or imagemagick)


  • Please log in to reply
6 replies to this topic

#1 adrianTNT

adrianTNT
  • Members
  • PipPipPip
  • Advanced Member
  • 146 posts

Posted 04 October 2006 - 11:07 PM

Hello, I thought it should be something easy but I cannot find a simple sample code for this...
I have more images that are saved as 250x250px on server and I need to display them on some page as lower size, e.g 125x125px.
I do not need to physically store them at the new size.
I thought it should be an easy way like:

<img src=" <? GD_resize('my_image.jpg',125,125);?> " width="250" height="187">

But I could not find a sample like this. Is there a way to resize an image like above?

Thank you.
- Adrian.

#2 brendandonhue

brendandonhue
  • Members
  • PipPipPip
  • Advanced Member
  • 65 posts

Posted 04 October 2006 - 11:11 PM

No, you can't mix outputting images and HTML like that. You can use imagecopyresampled() if you want to resize an image.

#3 printf

printf
  • Staff Alumni
  • Advanced Member
  • 889 posts

Posted 04 October 2006 - 11:13 PM

you have to call a remote script that dumps the resized image to the browser, you can't do it in the same page! A image is binary data, a web page is not! Create a page that takes a $_GET / $_REQUEST, then grabs the original image, resizes it, then dumps it to the browser! If the image doesn't exist, send a default image!

me!

#4 adrianTNT

adrianTNT
  • Members
  • PipPipPip
  • Advanced Member
  • 146 posts

Posted 04 October 2006 - 11:16 PM

by the above solutions is it required that the new image be physically saved on server?
What should the external script contain (if is a short code block).

Thank you.

#5 printf

printf
  • Staff Alumni
  • Advanced Member
  • 889 posts

Posted 05 October 2006 - 12:23 AM

by the above solutions is it required that the new image be physically saved on server?


NO

// make your <img> tag like so

<img src='/images.php?image=my_image.jpg' alt='' />


Download the the example ZIP file, I attached


me!

[attachment deleted by admin]

#6 adrianTNT

adrianTNT
  • Members
  • PipPipPip
  • Advanced Member
  • 146 posts

Posted 05 October 2006 - 12:43 AM

Thank you.

#7 simcoweb

simcoweb
  • Members
  • PipPipPip
  • Advanced Member
  • 1,102 posts
  • LocationCA

Posted 12 October 2006 - 07:00 PM

I came across this thread while looking for some relief regarding image resizing. I downloaded sprintf's 'example' script and it works great if you're calling a single pic.

What I'm doing is running a 'while' loop through the mysql results to display multiple profiles in some html. I was previously using a call like this:

while ($a_row = mysql_fetch_array($results)){
echo 
                "<div align='center'>
                  <table border='0' cellpadding='0' style='border-collapse: collapse' width='530'>
                    <tr>
                      <td colspan='2'>
                      <img border='0' src='images/top.gif' width='530' height='35'></td>
                    </tr>
                    <tr>
                      <td style='padding-left: 10px;' height='15' colspan='2'>
                      <h2>". $a_row['firstname'] ." ". $a_row['lastname'] . "</h2>
                      </td>
                    </tr>
                    <tr>
                      <td style='padding-left: 10px; padding-right: 10px; padding-top:5px; padding-bottom:5px' width='210' valign='top'><img src='images/photo/" . $a_row['photo'] . "'  width='200' height='225'></td>

etc. etc.

And it worked fine through the array. However, i'm using standard HTML tags for the image resizing which, of course, makes the pics all whacky. Therefore i'm desperately looking for a way to resize each image on the fly and came across your script.

Now, I've tried a couple of ways to produce the same results using your script like these:

<img src='/image_f.php?image=$photo' alt='' />

and

<img src='/images/photo/" . $a_row['photo'] . "' />

The second works fine but only displays the first pic or some of the pics but fails on many of them. Here's an example:

http://www.plateaupr...ge-a.php?page=3

Question is can this resize script be adapted to work in this enviroment where it's pulling multiple pics from the same folder, resizing them, and displaying them properly?

Thanks for the help!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users