SitePoint Sponsor

User Tag List

Page 6 of 6 FirstFirst ... 23456
Results 126 to 139 of 139
  1. #126
    SitePoint Member
    Join Date
    Jan 2008
    Posts
    0
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think it would be better to send the filename to your function, instead of $mysock[0] and $mysock[1].

    Something like this (I haven't tested it, so it might as well explode ...):

    function imageResize($image, $target) {
    list($width, $height) = getimagesize($image);

    [...]

    }

    And then call the function like this:

    <img src="images/sock001.jpg" <?php echo imageResize("images/sock001.jpg", 150); ?>>

  2. #127
    sequoia mcdowell
    SitePoint Community Guest
    Hmm... This isn't really resizing an image using PHP, it's resizing an image OUTPUT using HTML, and setting the h/w values with PHP. If anyone's interested in resizing the actual image w/PHP, I found a tut here: 4wordsystems.com/php_image_resize.php
    (don't mean to draw people away, if there is such a tutorial on this site, please replace my link w/yours)
    -Sequoia

  3. #128
    SitePoint Addict sorin21us's Avatar
    Join Date
    Mar 2009
    Posts
    278
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I used this function

    PHP Code:
    function createthumb($name,$filename,$new_w,$new_h)
    {
    $system=explode(".",$name);
    if (
    preg_match("/jpg|jpeg/",$system[1])){$src_img=imagecreatefromjpeg($name);}
    if (
    preg_match("/png/",$system[1])){$src_img=imagecreatefrompng($name);}
    $old_x=imageSX($src_img);
    $old_y=imageSY($src_img);
    if (
    $old_x $old_y
    {
    $thumb_w=$new_w;
    $thumb_h=$old_y*($new_h/$old_x);
    }
    if (
    $old_x $old_y
    {
    $thumb_w=$old_x*($new_w/$old_y);
    $thumb_h=$new_h;
    }
    if (
    $old_x == $old_y
    {
    $thumb_w=$new_w;
    $thumb_h=$new_h;
    }
    $dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);
    imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y); 
    if (
    preg_match("/png/",$system[1]))
    {
    imagepng($dst_img,$filename); 
    } else {
    imagejpeg($dst_img,$filename); 
    }
    imagedestroy($dst_img); 
    imagedestroy($src_img); 

    from here.

    See the DEMO when you login with demo and demo, and adding a photo to the demo profile.

  4. #129
    Joel
    SitePoint Community Guest
    Hi!

    This is a really good little tut/code snippet! Exactly what I was looking for!

    Thank you for sharing this!

    Itīs really appreciated!

  5. #130
    Kelvin
    SitePoint Community Guest
    Hi, I think you are not calling the function properly. You should use another variable to store the result of the function call, then echo the variable. Like this:
    <img src="xxx.jpg" <?php $result = imageResize($bigger[0],$bigger[1], 500);
    echo $result ?>>
    When you echo result, it will output width="xx", height="xx"

  6. #131
    SitePoint Member
    Join Date
    Jun 2009
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So how would I insert the result of $imageResize in the following PHP code?

    $imageurl = "<img src='".$prodimagedir.urlencode($row["product_image_small"])."' border='0' width='100' height='100' class='item_thumb'>";

    Thanks much for all the tips!
    sg

  7. #132
    Pablo Fierro
    SitePoint Community Guest
    Hello, This script is not working for my I do everything but I get no width, or height properties on the outcome html.

  8. #133
    cyberpulp
    SitePoint Community Guest
    Thanks Greg, works a treat, had an issue with IE resizing images after viewed full size and returning to a page viewing thumbs with size controlled by % of width and height, but this little gem sorted it.

  9. #134
    SitePoint Member
    Join Date
    Oct 2006
    Posts
    0
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i rewrote that to suit my needs. Thought i would share it
    function imageResize($image,$target) {

    $img = getimagesize($image);
    $width = $img[0];
    $height = $img[1];

    if ($width > $height) {
    $percentage = ($target / $width);
    } else {
    $percentage = ($target / $height);
    }

    $width = round($width * $percentage);
    $height = round($height * $percentage);

    return "width=\"$width\" height=\"$height\" border=\"0\"";

    }

  10. #135
    SitePoint Member
    Join Date
    Aug 2009
    Posts
    0
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the script. Everything is fine. However, the last part with img tag won't work because you are not actually printing out what is being returned. it should be changed to:


    <img src="images/sock001.jpg" <?=imageResize($mysock[0],
    $mysock[1], 150); ?>>

    Then it should work :) Thanks for the script pretty easy and fast.

  11. #136
    SitePoint Member
    Join Date
    Aug 2009
    Posts
    0
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the script. Everything is fine. However, the last part with img tag won't work because you are not actually printing out what is being returned. it should be changed to:


    <img src="images/sock001.jpg" <?=imageResize($mysock[0],
    $mysock[1], 150); ?>>

    Then it should work :) Thanks for the script pretty easy and fast.

  12. #137
    SitePoint Member
    Join Date
    Feb 2010
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try to use this picture resizing tool It works well! This is site softorbits.com/batch_picture_resize/

  13. #138
    SitePoint Guru
    Join Date
    Jan 2007
    Posts
    934
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    all this does is change the html attributes

  14. #139
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,788
    Mentioned
    151 Post(s)
    Tagged
    3 Thread(s)
    please note the date that this was first published: Jul 23, 2004

    Alot has changed since then!
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •