Forums

[resolved] Re-size image automatically (20 posts)

  1. fouadovic
    Member
    Posted 4 years ago #

    Hello :
    When i upload image in the admin area, the image has as default, its real size. Can i limit the width of the image (<450px) when uploading (Using GD LIB for exemple)?
    CSS proprety "max-width" don't work on IE6, so i have problems on displaying pages.
    Thanks

  2. taz72
    Member
    Posted 4 years ago #

    hi fouadovic

    I am using imagefromjpeg which i borrowed from a friend of mine which seems to work well... you can see it here http://www.estateagencies.co.za/demo

    The img src attribute looks like, displaythumb.php?imagewidth=450&picture=1234.jpg

    This is what my displaythumb.php looks like:

    --------------------------------------

    // usage : <img src="displaythumb.php?imagewidth=80&photoid=2874.jpg">

    $thumbname = $_GET[photoid];
    $directory = "/home/esp007/public_html/demo/photos";
    $widthimage = $_GET[imagewidth];
    $filename = $directory . '/' . $thumbname;
    $max = $_GET[max];
    //$filename = $thumbname;
    $new_h = $widthimage;
    // Content type
    header('Content-type: image/jpeg');
    // Get new sizes
    $src_img = imagecreatefromjpeg($filename);
    $origw=imagesx($src_img);
    $origh=imagesy($src_img);
    $ratio=$origw*$new_h;
    $new_w=$ratio/$origh;
    $dst_img = imagecreatetruecolor($new_w,$new_h);
    imagecopyresized($dst_img,$src_img,0,0,0,0,$new_w,$new_h,imagesx($src_img),imagesy($src_img));
    imagejpeg($dst_img);

    --------------------------------

  3. fouadovic
    Member
    Posted 4 years ago #

    Hi taz72 :
    Where i have to copy this code ?
    I don't see any option where put ma max size (exemple width : 450px and height : calculated "proportionnal") ?
    Thanks

  4. taz72
    Member
    Posted 4 years ago #

    hi fouadovic

    The code I listed is in the displaythumb.php file, so you copy that code and save it as displaythumb.php. You place the displaythumb.php within your publicly visible hosting space, then you call the image by <img src="displaythumb.php?imagewidth=450&photoid=1234.jpg">

    It is exactly the same as calling <img src="1234.jpg"> except you are resizing it by calling displaythumb.php

    The only thing I am not sure about is my photos are already in a folder called /photos, so if you upload via wordpress, I am not sure if you get the opportunity to specify a path to that image.

    I will dump the php file at http://www.estateagencies.co.za/displaythumb.zip for you.

  5. taz72
    Member
    Posted 4 years ago #

    The thumbnail it generates uses imagewidth to work out height, as it resizes proportionally.

  6. taz72
    Member
    Posted 4 years ago #

    You can see the result more clearly here:

    150px Wide View
    -------------------------------------------

    http://www.estateagencies.co.za/demo/displaythumb.php?imagewidth=150&photoid=1234.jpg

    550px Wide View

    --------------------------------------------

    http://www.estateagencies.co.za/demo/displaythumb.php?imagewidth=550&photoid=1234.jpg

  7. fouadovic
    Member
    Posted 4 years ago #

    I will see if i can use this script.
    I will reply soon.
    Thanks a lot taz72.

  8. taz72
    Member
    Posted 4 years ago #

    My Pleasure :)

  9. fouadovic
    Member
    Posted 4 years ago #

    taz72,
    In WP, where is the link to the image? Where i have to put this : <img src="displaythumb.php?imagewidth=450&photoid=1234.jpg"> ?
    In single.php, we have the function "the_content" taht display all the post.
    Thanks

  10. taz72
    Member
    Posted 4 years ago #

    Are you uploading the image via WordPress, or are you referencing to it via an <img> call?

    You should be able to upload the image using WordPress Upload, but do not insert it into the post as a thumbnail or anything. Once the upload is complete, in your post, you can call the image like such :

    <img src="http://www.yourwebsite.com/wp-content/uploads/displaythumb.php?imagewidth=150&photoid=yourimage.jpg">

    This should work quite fine :)

    I will do a test for you kwik, then send you the link and the post so u can see.

  11. taz72
    Member
    Posted 4 years ago #

    If you have a look at http://e-complaints.co.za I have published a test JPG using displaythumb.php

    I wrote a post, uploaded the full size JPG using WordPress but noted that wordpress creates a directory structure in /uploads so I had to modify the file structure a bit.

    The displaythumb.php file now looks like this:

    <?php

    $thumbname = $_GET[photoid];
    $directory = "/home/complain/public_html/wp-content/uploads/2007/10";
    $widthimage = $_GET[imagewidth];
    $filename = $directory . '/' . $thumbname;
    $max = $_GET[max];
    //$filename = $thumbname;
    $new_h = $widthimage;
    // Content type
    header('Content-type: image/jpeg');
    // Get new sizes
    $src_img = imagecreatefromjpeg($filename);
    $origw=imagesx($src_img);
    $origh=imagesy($src_img);
    $ratio=$origw*$new_h;
    $new_w=$ratio/$origh;
    $dst_img = imagecreatetruecolor($new_w,$new_h);
    imagecopyresized($dst_img,$src_img,0,0,0,0,$new_w,$new_h,imagesx($src_img),imagesy($src_img));
    imagejpeg($dst_img);

    ?>

    I hope this was helpful

  12. fouadovic
    Member
    Posted 4 years ago #

    I upload with WP.
    I try to make writing and uploading image easier, it's for a friend who will work with WP, he has not the experience to do this correctly.
    So, if he works in the admin area he must not send image in the text zone? he will just upload image, that's right?

  13. taz72
    Member
    Posted 4 years ago #

    Yes.. He can upload using WordPress, but not click "Send to Editor".. Instead he will need to click on the Post's Code View, then Click the [img] button, and place the URL to the image.

    Like :

    http://www.yoursite.com/wp-content/uploads/2007/10/displaythumb.php?imagewidth=150&photoid=yourpic.jpg

  14. taz72
    Member
    Posted 4 years ago #

    I would recommend he keeps a URL snippet handy so he does not have to retype the URL all the time though.

    I am using a database and PHP to generate my property listings automatically, so for me it is easier. I do not have to type anything in, it's all automated.

  15. fouadovic
    Member
    Posted 4 years ago #

    I don't think that will be easy for him.
    I thought there will be a solution with the upload form (in the "writhe post" page). When you upload the image, the size is edited (usign GD lib i think). Do you have an idea using this?
    Thanks

  16. taz72
    Member
    Posted 4 years ago #

    Sorry :( My knowledge is slightly limited in that area, but I would say the best would be to modify the WordPress source to do this for you.

  17. fouadovic
    Member
    Posted 4 years ago #

    that's the solution, put the code to generate images with limited size.
    But how to do it, that's the question :-)
    Me too, i'm not an expert in WP.

    taz72, thank you very much for your help.

  18. jrrl
    Member
    Posted 4 years ago #

    What you need is a plugin that hooks into the wp_handle_upload filter. This would let resize images to some maximum, change their type, autogenerate thumbnails, etc.

    Unfortunately, I don't have one on me right now. :-) But maybe I'll roll one this week. Sound like a nice little project for an evening.

  19. jrrl
    Member
    Posted 4 years ago #

    Flexible Upload looks like it might do the job for you.

  20. fouadovic
    Member
    Posted 4 years ago #

    jrrl :
    I installed this plugin, it works very well. That's what i'm looked for, thanks.

    Thank you jrrl and taz72 for your help.

    My english is not very well, excuse me ;-)

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.