• Resolved fouadovic

    (@fouadovic)


    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

Viewing 15 replies - 1 through 15 (of 19 total)
  • hi fouadovic

    I am using imagefromjpeg which i borrowed from a friend of mine which seems to work well… you can see it here https://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);

    ——————————–

    Thread Starter fouadovic

    (@fouadovic)

    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

    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 https://www.estateagencies.co.za/displaythumb.zip for you.

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

    You can see the result more clearly here:

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

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

    550px Wide View

    ——————————————–

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

    Thread Starter fouadovic

    (@fouadovic)

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

    My Pleasure ??

    Thread Starter fouadovic

    (@fouadovic)

    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

    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=”https://www.yourwebsite.com/wp-content/uploads/displaythumb.php?imagewidth=150&photoid=yourimage.jpg”&gt;

    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.

    If you have a look at https://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

    Thread Starter fouadovic

    (@fouadovic)

    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?

    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 :

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

    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.

    Thread Starter fouadovic

    (@fouadovic)

    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

    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.

Viewing 15 replies - 1 through 15 (of 19 total)
  • The topic ‘Re-size image automatically’ is closed to new replies.