/    Sign up×
Community /Pin to ProfileBookmark

Resize Image place holder

I have an image placeholder with dimension is [I]100Wx100H[/I].

I have an image named “[B]Image1[/B]” with dimension [I]50Wx50W[/I]. When I attach the image in to to image place holder ([I]$ImageHolder=$Image1[/I]). Image will be automatically rescaled to fit to image holder size: to be [I]100Wx100H[/I].

Now I have another image named “[B]Image2[/B]” with dimension [I]100Wx50W[/I]. When I attach the image in to to image place holder ([I]$ImageHolder=$Image2[/I]). Image will be automatically rescaled to fit to image holder size: to be [I]100Wx100H[/I]. At this time, the image then does not look right any more. How can and resize the image holder to be the same as the image file.
I use:
$hImage = getimagesize($Image2);
$Width = $hImage[0]; [I]// = 100[/I]
$Height = $hImage[1]; [I]// = 50[/I]

[B]How do I apply this $Width and $Height to resize the image placeholder?[/B]

(This happens at very begining of loading PHP)

Can someone give me a help? Thank you ?

to post a comment
PHP

9 Comments(s)

Copy linkTweet thisAlerts:
@bokehSep 06.2006 — [code=php]$hImage = getimagesize($Image2);
echo '<img src="whatever" '.$hImage[3].'>';[/code]
Copy linkTweet thisAlerts:
@teeleeauthorSep 06.2006 — Thank you! You sample is great but either it's not fit to my work or I'm not good enought to interpret it and merge it to my current code. Let me put it little more information where you or someone may help me out:

  • 1. In my case, I already have an image placeholder named "IMAGE_HOLDER" and it value is "$strImageHolderValue" defined in my HTML with the dimension is 100Wx100H.


  • 2. Here is the code

    $strImage = "Image.jpg";

    $strImageHolderValue = $strImage;


  • 3. And the result:

    If "image.jpg" = 50Wx50H => image resize to fit the image placeholder size (100Wx100H).

    However, if "image.jpg" = says, 100Wx50H => Image is resized to to be 100Wx100H. It's incorrect.


  • 4. Therefore, I look for something like following

    $strImage = "Image.jpg";

    $strImageHolderValue = $strImage;

    $hImage = getimagesize($strImageFilename);

    // IMAGE_HOLDER.width = $hImage[0];

    // IMAGE_HOLDER.height = $hImage[1];

    // Or some how getting the handler of IMAGE_HOLDER and define its width and height

    // Or any other method


  • Thanks for the help
    Copy linkTweet thisAlerts:
    @bokehSep 06.2006 — I'm baffled! Are you trying to resize the image to fit a space or set the width and height in the mark-up so they match the image dimmensions.
    Copy linkTweet thisAlerts:
    @teeleeauthorSep 06.2006 — No! I'm trying to make the image placeholder readjusts itself to match the image size
    Copy linkTweet thisAlerts:
    @DJsACSep 07.2006 — [code=html]<img name="IMAGE_HOLDER" src="<?php echo $strImageHolderValue; ?>" width="<?php echo $hImage[0];?>" height="<?php echo $hImage[0];?>" alt="<?php echo $strImageAltText;?>" />[/code]OR
    [code=php]<?php
    echo "<img name="IMAGE_HOLDER" src="".$strImageHolderValue."" width="".$hImage[0]."" height="".$hImage[0]."" alt="".$strImageAltText."" />";
    ?>
    [/code]
    Copy linkTweet thisAlerts:
    @bokehSep 07.2006 — No! I'm trying to make the image placeholder readjusts itself to match the image size[/QUOTE]That's what the code posted does. If you want more specific help you will need to post the relevant section.
    Copy linkTweet thisAlerts:
    @teeleeauthorSep 07.2006 — Thank you for all help. It works like a champ. I'm very appreciated
    Copy linkTweet thisAlerts:
    @bokehSep 07.2006 — [code=php]width="".$hImage[0]."" height="".$hImage[0]."" [/code][/QUOTE]No need for all that mucking about. All that text is output by [I]getimagesize()[3][/I]
    Copy linkTweet thisAlerts:
    @DJsACSep 07.2006 — No need for all that mucking about. All that text is output by [I]getimagesize()[3][/I][/QUOTE]
    I thought I'd go ahead and put it in so he sees what's going on ?

    your script was the same thing, but to someone that doesn't know that much php it doesn't "look" like what he wanted...(I guess)

    and it should have been [0] and [1] :rolleyes:
    ×

    Success!

    Help @teelee spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.20,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...