Jump to content

Resizing an image (by GD or imagemagick)


adrianTNT

Recommended Posts

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.
Link to comment
Share on other sites

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!
Link to comment
Share on other sites

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

NO

// make your <img> tag like so

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


Download the the example [b]ZIP[/b] file, I attached


me!

[attachment deleted by admin]
Link to comment
Share on other sites

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:

[code]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>[/code]

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:

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

and

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

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:

[url=http://www.plateauprofessionals.com/display-page-a.php?page=3]http://www.plateauprofessionals.com/display-page-a.php?page=3[/url]

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!
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.