Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Regular Coder
    Join Date
    May 2011
    Posts
    303
    Thanks
    29
    Thanked 0 Times in 0 Posts

    thumbnail func help

    Hi

    hope some one can help me fix, here is how i call it:
    PHP Code:
    create_thumb($aConfig$files$new_name$thumbDir .'/'$album_id .'/'); 
    and here's the func:
    PHP Code:
        function create_thumb(array $aConfig$image_file$name$thumbDir) {
            
    $iDimension getimagesize($image_file); 
            
    $type $iDimension[2];
            echo 
    'Type: '$type;
            
            if (
    $type == "image/jpeg") { $tempThumb imagecreatefromjpeg($image_file); }
            elseif (
    $type == "image/bmp") { $tempThumb imagecreatefromwbmp($image_file); }
            elseif(
    $type == "image/png") { $tempThumb imagecreatefrompng($image_file); }
            elseif (
    $type == "image/gif") { $tempThumb imagecreatefromgif($image_file); }

            
    $width $iDimension[0]; // uploaded image width
            
    $height $iDimension[1]; // uploaded image height
            
            
    $ratio $width $height// calculate the ratio

            
    if ($ratio ) {
                
    $newW $aConfig['custom_pixels'];
                
    $newH $aConfig['custom_pixels'] / $ratio;
            } else {
                
    $newH $aConfig['custom_pixels'];
                
    $newW $aConfig['custom_pixels'] * $ratio;
            }
        
            
    $thumb imagecreatetruecolor($newW$newH);
        
            
    //the resizing is going on here!
            
    imagecopyresampled($thumb$tempThumb0000$newW$newH$width$height);
        
            
    //finally, save the image
            
    imagejpeg($thumb$thumbDir .'/thumb_' $name);
            
            
    // clean up
            
    imagedestroy($thumb);
            
    imagedestroy($tempThumb);
        } 
    I don't see the problem, any help............
    Thanks.
    Last edited by Chris-2k; 07-27-2012 at 11:20 PM.

  • #2
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,537
    Thanks
    45
    Thanked 259 Times in 256 Posts
    What's the issue you're having? The code looks OK, not withstanding I donno why you're multiplying or dividing by the ratio on only the height...

  • #3
    Regular Coder
    Join Date
    May 2011
    Posts
    303
    Thanks
    29
    Thanked 0 Times in 0 Posts
    it's just not uploading.

  • #4
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,537
    Thanks
    45
    Thanked 259 Times in 256 Posts
    You've tested out each step, echo'ed to make sure variables are what you expect, etc? And that the directory is writable?

  • Users who have thanked Keleth for this post:

    Chris-2k (07-27-2012)

  • #5
    Senior Coder
    Join Date
    Sep 2010
    Posts
    2,218
    Thanks
    15
    Thanked 253 Times in 253 Posts
    PHP Code:
    create_thumb($aConfig$files$new_name$thumbDir .'/'$album_id .'/');

    function 
    create_thumb(array $aConfig$image_file$name$thumbDir
    What is the word array doing in that second line? If $aConfig is an array, php will know it already.

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    array is added to a function signature to ensure its datatype. It guarantees that the item provided is an array. You do the same thing with objects, and if you want you can override the error handling to provide datatype strength to all custom PHP functions with whatever datatypes you want.

    What is this: imagecopyresampled($thumb0, $tempThumb, 0, 0, 0, 0, $newW, $newH, $width, $height); ? There is no $thumb0 declared anywhere. That has to be a valid resource created by the imagegd.

  • The Following 2 Users Say Thank You to Fou-Lu For This Useful Post:

    Chris-2k (07-27-2012), DrDOS (07-27-2012)

  • #7
    Regular Coder
    Join Date
    May 2011
    Posts
    303
    Thanks
    29
    Thanked 0 Times in 0 Posts
    This is what iis in my config;
    PHP Code:
    $config['custom_pixels']                    = $_POST['max_dimensions']; 
    As you see my func above, what could the problem be?

    all typos are fixed fyi.

  • #8
    Regular Coder
    Join Date
    May 2011
    Posts
    303
    Thanks
    29
    Thanked 0 Times in 0 Posts
    Ok i've
    PHP Code:
    echo 'thumbnail: '$aConfig['custom_pixels']; 
    get nothing, then i did:

    PHP Code:
                // Create the thumbnail
                
    if(isset($aConfig['custom_pixels']) && !empty($aConfig['custom_pixels']) && is_numeric($aConfig['custom_pixels'])) {
                    
    create_thumb($aConfig$url$new_name$thumb);
                } else {
                    
    trigger_error('<div align="center">Cannot create your thumbnail; ensure GD extension is loaded.</div>'E_USER_WARNING);
                } 
    and im getting the error..............

  • #9
    Senior Coder
    Join Date
    Sep 2010
    Posts
    2,218
    Thanks
    15
    Thanked 253 Times in 253 Posts
    Do you have an input in your form named max_dimensions ?

  • #10
    Regular Coder
    Join Date
    May 2011
    Posts
    303
    Thanks
    29
    Thanked 0 Times in 0 Posts
    Yea ive checked that, when i echo $aConfig['custom_pixels'] notin's there

  • #11
    Senior Coder
    Join Date
    Sep 2010
    Posts
    2,218
    Thanks
    15
    Thanked 253 Times in 253 Posts
    I don't see where you convert $config['custom_pixels']
    to $aConfig['custom_pixels'] ?

    Sometimes it's easier to write you own code from the top down than to modify someone else's, because you know what everything does.
    Last edited by DrDOS; 07-28-2012 at 02:46 AM.

  • #12
    Regular Coder
    Join Date
    May 2011
    Posts
    303
    Thanks
    29
    Thanked 0 Times in 0 Posts
    $aConfig is passed to the func... So then I c an use $aConfig['custom_pixels']??

  • #13
    Senior Coder
    Join Date
    Sep 2010
    Posts
    2,218
    Thanks
    15
    Thanked 253 Times in 253 Posts
    Do a print_r of $aConfig and see what you get, you are definitely missing some data somewhere. When you work with any kind of array, print_r is you friend and can find problems you didn't know you would have.

  • Users who have thanked DrDOS for this post:

    Chris-2k (07-28-2012)

  • #14
    Regular Coder
    Join Date
    May 2011
    Posts
    303
    Thanks
    29
    Thanked 0 Times in 0 Posts
    Ok done it mate, it seem its not picking up: . [custom_pixels] =>

    here's my input:
    Code:
            <tr>
    		<td><h2>Desired Width:</h2></td>
            <td><select name="max_dimensions">
                        <option value="50">None</option>
                        <option value="90">90px x 90px</option>
                        <option value="200">200px x 200px</option>
                        <option value="300">300px x 300px</option>
                        <option value="400">400px x 400px</option>
    					<option value="500">500px x 500px</option>
    				</select><font color="Red" size="-1"> - Optional</font></td></tr>
    help!!!!!!!!!!!!!!!!

  • #15
    Senior Coder
    Join Date
    Sep 2010
    Posts
    2,218
    Thanks
    15
    Thanked 253 Times in 253 Posts
    You can define or re-define any array element at any time in the process.
    Put this line below where you have defined:
    PHP Code:
     $config['custom_pixels']   

    $aConfig['custom_pixels']  = $config['custom_pixels']; 
    That should fix it.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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