www.webdeveloper.com
Results 1 to 3 of 3

Thread: php image uploader messes up images

  1. #1
    Join Date
    Feb 2011
    Posts
    17

    php image uploader messes up images

    hello everyone
    I try to modify a fancy image uploader script for my needs, but I can't.
    The problem with this script is that it behaves strangely with some images e.g. saves only the first frame of an aPNG, fills the transparent pixels with white(or any other color I set), etc.
    however, if I completely remove the part that does this, it can't resample the image if bigger than maxW and maxH and simply won't save the images(aka it fails).
    here you can try out the original, unmodified one: http://adolf94.x10.mx/php_ajax_image_upload/index_.php
    how I want it to look like: http://adolf94.x10.mx/php_ajax_image_upload/index.php
    and a gallery to view the images: http://adolf94.x10.mx/xfx10/index.php

    pastebin sources of the files needed to modify:
    ajaxupload.php
    index.php

    Thanks in advance
    Adolf

  2. #2
    Join Date
    Feb 2011
    Posts
    17
    as I said I could isolate the part that messes with the pic.
    I could put it into an if statement to resample only if $height_orig > $maxH or $width_orig > $maxW
    but if that statement isn't used, then the image won't be created.
    it looks like I have to put a function outside that statement that could replace the imagecopyresampled
    PHP Code:
    if($height_orig $maxH OR $width_orig $maxW){
        
    $image_p imagecreatetruecolor($fwidth$blank_height);
        
    $white imagecolorallocate($image_p$colorR$colorG$colorB);
        
    imagefill($image_p00$white);
        switch(
    $filetype){
            case 
    "gif":
                
    $image = @imagecreatefromgif($_FILES[$fileName]['tmp_name']);
            break;
            case 
    "jpg":
                
    $image = @imagecreatefromjpeg($_FILES[$fileName]['tmp_name']);
            break;
            case 
    "jpeg":
                
    $image = @imagecreatefromjpeg($_FILES[$fileName]['tmp_name']);
            break;
            case 
    "png":
                
    $image = @imagecreatefrompng($_FILES[$fileName]['tmp_name']);
            break;
        }
    @
    imagecopyresampled($image_p$image0$top_offset00$fwidth$fheight$width_orig$height_orig);
    }
    // here would come a function to replace imagecopyresampled 
    Last edited by Adolf1994; 05-28-2011 at 06:57 PM.

  3. #3
    Join Date
    Feb 2011
    Posts
    17
    finally I managed to make it work.
    I updated the pastebin links to let you look at it.
    Of course I give credits to AT Web Results for this wonderful image uploader.
    Of course, here is the result: http://adolf94.x10.mx/php_ajax_image_upload/

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles