SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Wizard
    Join Date
    Oct 2005
    Location
    London
    Posts
    1,678
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    image sizing problemo

    Hi,

    Im having this problem. I have an image resizing script going on. Im using the getimagesize function and then a function thats similar to the sitepoint image resizing script.

    What im doing is finding the width and height using imageresize and then if its more than a certain number im populating a variable with a desried resize value. This is then used later in the sitepoint image resize script.

    Heres the code:

    PHP Code:
     $imagearray getimagesize($file);
    print_r($imagearray);
    if(
    imagearray[0] || imagearray[1] >= 425)) {

    $sizeup 425;
    }

    else {
    $sizeup 0;

    right so larger images ( larger than 425) are sized down t o425 correctly....problem is smaller images are now sized up to 425.

    What am i doing wrong?

    Thanks

  2. #2
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if(imagearray[0] || imagearray[1] >= 425)) {
    That means if the image width is set (non zero) or the height is greater or equal to 425, resize it. I'm sure you don't mean to resize all images that have a width?

  3. #3
    SitePoint Wizard
    Join Date
    Oct 2005
    Location
    London
    Posts
    1,678
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Right i though that was saying if the first array element or the second array element are larger than 425 then.... ha, what an idiot! I really should know better!

    so should it be:

    PHP Code:
    if(imagearray[0] >= 425 || imagearray[1] >= 425)) { 
    right?

    Sorry i cant test it at the moment

  4. #4
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, that now says 'if the width or height is greater than or equal to 425, resize it'.

  5. #5
    SitePoint Wizard
    Join Date
    Oct 2005
    Location
    London
    Posts
    1,678
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Great thanks for that mark, sometimes i just dont spot these things because im looking for something more complex. I suppose it comes with experience.

    Thanks

  6. #6
    SitePoint Enthusiast
    Join Date
    Sep 2005
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by elduderino View Post
    ....
    right so larger images ( larger than 425) are sized down t o425 correctly....problem is smaller images are now sized up to 425.
    am not sure if you already solved your image resizing issue, but for you and all other devs like you looking for a way to transform images on the fly, you might want to check the open-source projectAsido: there are a lot of useful features (http://www.asido.info/about/features/), including various types of image resize - like fit resize (resize if bigger) and frame resize (force-fit), watermarking, image copy, cropping, etc. It can use various platforms: not only GD but ImageMagick too (either via shell or via any of the php extensions like php_magickwand.dll or php_imagick.dll). Here's the list of drivers: http://www.asido.info/about/drivers/

    It seems that what you need is the fit resize: http://www.asido.info/about/features/#fit
    This type of resize will attempt to resize your image only if it is bigger then the provided set of width and height (as I call it the "resize frame"). So, smaller images that fit inside the "resize frame" will not be resized. They will be resized only if they are bigger - and bigger means that either of its dimensions is bigger than the corresponding dimention of the "resize frame".


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
  •