SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Addict
    Join Date
    Aug 2007
    Posts
    270
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Image Resizing help/scripts

    Hi guys

    I have been trying to find a script or some code that can help users resize their pictures online, as i have a site where people upload lots of images.

    I have orignially found a script which is ok but it doesnt work with bmp files, no idea why i have tryed to contact the people who set it up with no luck, if anyones really clever maybe you could try to figure out whats gone wrong with it, ill post the link i hope it doesnt get marked as spam though

    http://www.worldofchat.co.uk/resize/pictureresizing.php

    Other than that does anyone know of an easy way to create an online image resizer, or know of any scripts that could help me, ive had a good look around with no luck.

    Yours tearing my hair out

    Woc
    ]

  2. #2
    Team SitePoint santouras's Avatar
    Join Date
    Jul 2006
    Location
    planet earth
    Posts
    276
    Mentioned
    16 Post(s)
    Tagged
    0 Thread(s)
    looks like its being detected as a WBMP instead of a BMP file.

    Warning: imagecreatefromwbmp() [function.imagecreatefromwbmp]: '/tmp/phpbAY89X' is not a valid WBMP file

    from the PHP Manual
    for .bmp files, convert them with bmp2png, then you can use this files in gd
    http://cetus.sakura.ne.jp/softlab/b2p-home/
    my utility belt tells me its to the bar batman

    read the manual then google it then do a search THEN post....

  3. #3
    SitePoint Addict
    Join Date
    Aug 2007
    Posts
    270
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm have you any idea what changes i could make to get this working for bmp files ?

    Woc
    ]

  4. #4
    SitePoint Mentor silver trophy
    Rubble's Avatar
    Join Date
    Dec 2005
    Location
    Cambridge, England
    Posts
    2,443
    Mentioned
    82 Post(s)
    Tagged
    3 Thread(s)
    Looks like bmp images are not supported by GD and a recomended way around this is to convert them to png format.
    http://uk2.php.net/manual/en/functio...tefromwbmp.php

    You could use imagemagick which supports bmp along with loads of other formats.

    If you check out my site I have a bit of code you could modify but you will need to put some verification into the code to stop malicious input.

  5. #5
    SitePoint Addict
    Join Date
    Aug 2007
    Posts
    270
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hmmm i dont know very much about php at all, thats all gone over my head a bit lol

    Woc
    ]

  6. #6
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Hard way - sit down and learn about the intricate differences in image file formats, a bit of php, a few functions and patch the script up....

    Easy way - Dont allow users to upload BMP's!

    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  7. #7
    SitePoint Mentor silver trophy
    Rubble's Avatar
    Join Date
    Dec 2005
    Location
    Cambridge, England
    Posts
    2,443
    Mentioned
    82 Post(s)
    Tagged
    3 Thread(s)
    Its hard if you do not know much about php, there was somebody posting links to his software on the forum which may work for you: http://sourceforge.net/projects/asido/ I have not tried it.

    The code below will resize an image but it would need user input validation and possibly other modifications to get it how you want.
    To try it out save it as a php file on your server in a folder, CHMOD the folder to 777 and navigate to the file. You will see a form to browse for the image on your hard drive, press submit and the image ( as long as ImageMagick is installed ) will be uploaded to the same folder.

    You may need to change convert to something like /user/local/bin/convert Post to let me know how you get on.

    This will work with about 100 image formats.

    PHP Code:
    <?php 
    // If the form has been submitted do this 
    if ( $Submit ) {   

    // Temporary upload image name 
    $original_image $_FILES['filename']['tmp_name']; 

    // Get the image dimensions 
    $size=GetImageSize$original_image ); 

    // Name to save the image as - in this case the same as the original 
    $new_image $_FILES['filename']['name']; 

    // Maximum image width 
    $max_width "200"

    // Maximum image height 
    $max_height "90"

    // Resize the image and save 
    exec("convert -size {$size[0]}x{$size[1]} $original_image -thumbnail {$max_width}x{$max_height} $new_image"); 

    echo 
    "File uploaded<br>"

    echo 
    "<img src=\"".$new_image."\">"

    else { 
    ?> 
    <p>File to upload:</p> 
    <form method="post" action="<?php echo $PHP_SELF?>" enctype="multipart/form-data"> 
    <input type="file" name="filename"  /> 
    <input type="Submit" name="Submit" value="Submit" /> 
    </form> 
    <?php ?>


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
  •