Jump to content

marvelade

Members
  • Posts

    11
  • Joined

  • Last visited

    Never

Posts posted by marvelade

  1. PS: I know the existence of PDO but it can be disabled by the hosting provider (I know some hoster doing this...)

     

     

    There are also hosters that keep register_globals On, but that generally means that their service sucks.

    Find one hosting partner that u are comfortable with (preferrably *not* a free one); they should have enough PHP expertise to realise what decent settings are instead of basing their settings on some blog post saying that PDO is not implemented well in PHP4 (while they ru PHP5) and that register_globals is a handy tool for developers...

     

    Most hosting companies know a lot about Linux/apache but nothing about PHP, unfortunately.

     

    greetz,

    Marv

     

  2. Hi All,

     

    I'm struggling with an image-operation. I'm trying to scale, flip, move and rotate an image. However the imagerotate function is bugging me.

     

    Because imagerotate() also moves the image down in relation to it's container we have to cancel that movement out.

    the implicit movement equals the width of the original image, multiplied by the sine of the rotation angle so I subtract that amount from my delta_y. Here's the code:

     

    <?php
    $scale = isset($_GET['scl']) ? floatval($_GET['scl']) : 0.8;
    $delta_x = isset($_GET['dx']) ? intval($_GET['dx']) : 10;
    $delta_y = isset($_GET['dy']) ? intval($_GET['dy']) : 20;
    $rotation = isset($_GET['rot']) ? intval($_GET['rot']) : 30;
    $flip = isset($_GET['flip']) &&  $_GET['flip']=="true" ? true : false;
    
    
    define("OUTPUTIMAGE", true);
    
    
    // manipulate original image
    
    // get the name
    $userpic_path = "../userpics/waldo.jpg";
    
    // convert to image resource
    $userpic_image = imagecreatefromjpeg($userpic_path);
    
    // prepare the container
    
    $userpic_size_array = getimagesize($userpic_path);
    $old_width = $userpic_size_array[0];
    $old_height = $userpic_size_array[1];
    
    
    $im = imagecreatetruecolor($old_width, $old_height);
    
    // move, scale & flip	
    
    $new_width = $old_width * $scale;
    
    $new_height = $old_height * $scale;
    
    if($rotation != 0)
    {
    	//imagerotate() performs an implicit move so we have to cancel that out
    	$rotation_radians = $rotation * (M_PI / 180);
    	$delta_y -= $new_width * sin($rotation_radians);
    }
    
    imagecopyresampled($im, $userpic_image, $delta_x, $delta_y, 0, 0, $new_width, $new_height, $old_width, $old_height);
    
    // prepare the transparent color
    $transp = imagecolorallocatealpha($im, 0, 0, 0, 0);
    
    // rotate
    $im = imagerotate($im, $rotation, $transp, false);
    
    
    
    
    
    if(OUTPUTIMAGE)
    {
    header("Content-type: image/png");
    imagepng($im, "", 0);
    imagedestroy($im);
    }
    
    ?>
    

     

    The result can be found here:

    http://www.marvelade.com/projects/devoslemmens/imgcrop/pages/png_generator.php?scl=1&dx=0&dy=0&rot=45&flip=false

     

    feel free to play around with the GET variables as you please.

     

    the original image is here:

    http://www.marvelade.com/projects/devoslemmens/imgcrop/userpics/waldo.jpg

     

    All help, remarks, comments are very much appreciated.

     

     

    Best regards and thanks in advance,

    Marvelade

  3. 1) For a more readable output do this instead:

     

    echo '<pre>' . print_r($result,true) . '</pre>';
    

     

    2) When you've completed a tutorial on how associative arrays work you will understand. there's tons of explanations on the internet far better than waht I can explain here :)

     

    3) .= means you glue a string to another variable

     

    $a = "Hello";
    $a.= " Moon";
    
    echo $a; // this will output "Hello Moon".

     

    actually this:

     

    $a .= " Moon";

     

    does the same as

    $a = $a . " Moon";

     

    but it's a little shorter to write.

     

    greetz,

    Marv

     

     

  4. your 2 snippets checks 2 different things, but since PHP is such a forgiving language (except when u forget a semicolon ;-) ) it will evaluate the existance of a variable as not false and the abscence of it as not true. Other languages would just say "argument should be of type BOOLEAN" or something similar. PHP does its best to try to figure out what you mean if it's not what it expects.

     

     

    grtz,

    Marv

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.