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 28
  1. #1
    New to the CF scene
    Join Date
    Feb 2007
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Get part of screen as image

    Hello all I'm new one here... Hope you'll help newbie programmer...

    Is there any way in PHP to get part of browser screen as JPEG (Or any other type) image?

    To concrete:

    Using this code

    Code:
      Function GenHexagons($R, $CountX, $CountY, $Left, $Top){
       	$StepX = 1.5 * $R;
       	$stepY = Sqrt(3) * $R;
       	
    		For($i = 0; $i < $CountX; $i++){
    	    $X = $Left + Round( $StepX * $i );
    	    
    			For($j = 0; $j < $CountY; $j++){
    			  $Y = $Top + Round( $stepY * ( $j + 0.5 * ($i % 2)));
    			//	echo '<p><a href="'. $Y .'">Y = '.$Y.'</a></p>';
    			//	echo '<p><a href="'. $X .'">X = '.$X.'</a></p>';
    				echo  "<img src=\"hex.png\" style=\"position: absolute; top:".$Y."px; left:".$X."px; \" alt=\"\" />" ;
    			}
    		}
    	 
      }
    
    GenHexagons(21, 5, 5, 50, 0);
    I get somthing like this:




    PHP code makes so, that hexagon image is repeating horizontally and vertically and I get many images. But it would be great to combine them as one file image... Any idea?


    Thanks
    Last edited by chekura; 02-25-2007 at 12:28 PM.

  • #2
    Regular Coder westmatrix99's Avatar
    Join Date
    Dec 2006
    Location
    South Africa
    Posts
    307
    Thanks
    12
    Thanked 0 Times in 0 Posts
    What is this for

    GenHexagons(21, 5, 5, 50, 0);

    Cheers
    Thanks for you support!

  • #3
    New Coder
    Join Date
    Feb 2007
    Posts
    21
    Thanks
    1
    Thanked 0 Times in 0 Posts
    westmatrix99

    This are function arguments

    GenHexagons(21, 5, 5, 50, 0); = GenHexagons($R, $CountX, $CountY, $Left, $Top)

    where R = Hexagons side, Countx= Number of Hexagons to be displayed horizontally, CountY= Number of Hexagons to be displayed vertically, Left= Left Margin, Top = top margin.

    You must call the funtction to make it work, otherwise it wont work.
    cheers
    Last edited by Sandrix; 02-25-2007 at 01:38 PM.

  • #4
    Regular Coder westmatrix99's Avatar
    Join Date
    Dec 2006
    Location
    South Africa
    Posts
    307
    Thanks
    12
    Thanked 0 Times in 0 Posts
    Then make it

    GenHexagons(21, 1, 1, 50, 0);

    That should solve so many of them showing and only one should show.
    Thanks for you support!

  • #5
    New Coder
    Join Date
    Feb 2007
    Posts
    21
    Thanks
    1
    Thanked 0 Times in 0 Posts
    westmatrix99

    Lol ) I'm not sure that you understand the code that chekura provided .

    coz if he does what you say then the function will show only one hexagon, but chekura wants to generate the hexagonal grid as one image, not just <img scr="hex.gif" /> lol... he didn't mention that he wants to display a hexagon, what he meant is that he wants to generate an image filled with hexagons.. in other words he wants to merge all those hexagons in to one and display them as one image. otherwise why whould he use this function lol? to display one image?
    Last edited by Sandrix; 02-25-2007 at 02:32 PM.

  • #6
    New Coder
    Join Date
    Feb 2007
    Posts
    21
    Thanks
    1
    Thanked 0 Times in 0 Posts
    so? any1?

    I need this too

    I've got an Idea but I don't know how to make it work

    Ok here is the image watermark scritpt:

    PHP Code:
    <?

    class watermark {
       public static function 
    emboss($pic1$patt) {

          
    header("Content-type: image/png");
          
    $source imagecreatefromjpeg($pic1); // Source
          
    $pattern imagecreatefromjpeg($patt); // pattern

          
    list ($width$height) = getimagesize($pic1);
          list (
    $widthpatt$heightpatt) = getimagesize($patt);

          
    $new_width $width;
          
    $new_height $width $widthpatt $heightpatt;

          if (
    $new_height $height) {
        
    $offset intval(($new_height $height) / 2);
          }elseif (
    $new_height $height) {
        
    $offset intval(($new_height $height) / 2);
           } else {
           
    $offset 0;
            }

        
    $image_p imagecreatetruecolor($new_width$new_height);
        
    $pattern imagecreatefromjpeg($patt);
         
    imagecopyresampled($image_p$pattern0000$new_width$new_height$widthpatt$heightpatt);

        
    $im imagecreatetruecolor($width$height);
            for (
    $y 0$y $height$y ++) {
           for (
    $x 0$x $width$x ++) {
             
    $colors imagecolorsforindex($sourceimagecolorat($source$x$y));
             
    $pattern_color imagecolorsforindex($image_pimagecolorat($image_p$x, ($y $offset)));
            
                 
    //changes brightness depending on luminance
            
    if (($y $offset +1) > && ($y $offset) < ($new_height -1)) {
              
    $brightness abs(($pattern_color['red'] * 50 255) - 50);
               if (
    $pattern_color['red'] < 150) {
                 
    $change true;
               } else {
                  
    $change false;
                  
    $tally 0;
               }

               if (
    $change && $tally 2) {
                 
    $highlight 1.8;
                 
    $tally ++;
               } else {
                 
    $highlight 1;
               }
               
    $brightness $brightness $highlight;
            } else {
                
    $brightness 0;
            }
            
    $r = (($colors['red'] + $brightness) > 255) ? 255 : ($colors['red'] + $brightness);
            
    $g = (($colors['green'] + $brightness) > 255) ? 255 : ($colors['green'] + $brightness);
            
    $b = (($colors['blue'] + $brightness) > 255) ? 255 : ($colors['blue'] + $brightness);
            
    $test imagecolorallocate($im$r$g$b);
            
    imagesetpixel($im$x$y$test);
           }
            }

        
    imagepng($im);
        
    imagedestroy($im);
       }
    }

    watermark::emboss("apply-to-image.jpg""pattern.jpg");

    ?>
    and maybe someone(php guru) could make it to work with GenHex() function?
    I mean, that some background shape(or image) will be watermarked with hexagons so the result would be the single image.
    Last edited by Sandrix; 03-02-2007 at 06:21 PM.

  • #7
    Regular Coder westmatrix99's Avatar
    Join Date
    Dec 2006
    Location
    South Africa
    Posts
    307
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Lightbulb

    How big can you make this image?
    What I mean is, if you take one hexagon image how big can you make it.
    Then add the other images repeating horizontally and vertically inside that big one.
    How would that code look?
    Cheers
    Thanks for you support!

  • #8
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    Quote Originally Posted by chekura View Post
    Hello all I'm new one here... Hope you'll help newbie programmer...

    Is there any way in PHP to get part of browser screen as JPEG (Or any other type) image?
    No. PHP is server-side only. To alter an image with PHP you would have to have post it to a server with PHP or the image file would have to be on the server.

  • #9
    New Coder
    Join Date
    Feb 2007
    Posts
    21
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by westmatrix99 View Post
    How big can you make this image?
    What I mean is, if you take one hexagon image how big can you make it.
    Cheers

    As big as I want I think Function is universal.

    BTW

    Then add the other images repeating horizontally and vertically inside that big one.
    How would that code look?
    That's what I said in previous post.. to generate an image and then watermark it with my hexagons, using the algorithm provided in first post.

    But how?

  • #10
    Regular Coder Armondo's Avatar
    Join Date
    Feb 2007
    Posts
    144
    Thanks
    3
    Thanked 0 Times in 0 Posts
    nevermind...i just read the above posts.
    ..
    ▲ ▲

  • #11
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,776
    Thanks
    19
    Thanked 155 Times in 146 Posts
    Quote:
    Originally Posted by chekura
    Hello all I'm new one here... Hope you'll help newbie programmer...

    Is there any way in PHP to get part of browser screen as JPEG (Or any other type) image?


    No. PHP is server-side only. To alter an image with PHP you would have to have post it to a server with PHP or the image file would have to be on the server.
    I don;t know enough about PHP's image functions to know for sure, but it seems like you might be able to accomplish this with a combination of Javascript and PHP...

    With JS, you can grab all or some of the HTML/CSS on a page, by selecting elements on the page, grabbing the HTML/CSS inside of the selection, and dumping it in a JS variable. Then, via the POST or maybe AJAX, you could send the contents of this variable (the selected HTML/CSS) to a PHP file...

    What I don;t know is if, at this point, you can convert the raw HTML/CSS into an image using PHP's image functions....It seems like with some math, logic and a little patience, you might be able to create a "screenshot" image file of part or all of a web page that way...The only thing that I can think of that might not translate well is the default GUI of the browser (i.e., scroll bars, form controls)..

    Sure would be interested to know if this is possible, or if someone has ever attempted this, from someone who knows more about the image functions...
    Last edited by chump2877; 03-03-2007 at 11:12 PM.
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!

  • #12
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    You could, in theory, accomplish this, but the codebase would be ridiculously huge, not worth the effort, and not really accurate as you would only be generating what you -think- the page would look like in the user's browser.

  • #13
    New Coder
    Join Date
    Feb 2007
    Posts
    21
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I don't get it. I just want to watermark the image with hexagons and want someone to help me with this so where is the problem?

  • #14
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    This will generate the hexagons image:
    PHP Code:
    <?php

    // Misc. Settings
    $hexagon_width 30;
    $hexagon_height 25;
    $hexagon_spacer 3;
    $hexagon_columns 5;
    $hexagon_rows 5;

    header("Content-type: image/png"); // send PNG header
    $img imagecreate(150,175); // create the image pointer
    imagecolorallocate($img,255,255,255); // set the background color
    $color imagecolorallocate($img,255,128,0); // set the hexagon color

    // Custom function to (hopefully) allow scaling of hexagon shapes
    function create_hexagon($img$color$height 25$width 30$left_offset 0$top_offset 0)
    {
        
    $points = array($left_offset,($height 2) + $top_offset// point 1 (left)
                        
    (($width 1) + $left_offset),$top_offset// point 2 (left-top)
                        
    (($width 3) + $left_offset),$top_offset// point 3 (right-top)
                        
    $width $left_offset,($height 2) + $top_offset// point 4 (right)
                        
    ($width 3) + $left_offset,$height $top_offset// point 5 (right-bottom)
                        
    ($width 1) + $left_offset,$height $top_offset); // point 6 (left-bottom)
        
    imagefilledpolygon($img,$points,6,$color);    
    }

    // Loops for columns & rows of hexagons
    for($i 0$i $hexagon_columns$i++)
    {
        for(
    $j 0$j $hexagon_rows$j++)
        {
            
    $top_offset = ($i 2) == ? ($hexagon_height 2) + $hexagon_spacer 0// Add a topspacer to odd numbered rows so the hexagons interlock
            
    create_hexagon($img$color$hexagon_height$hexagon_width, (($hexagon_width 3) + $hexagon_spacer) * $i$j * ($hexagon_height $hexagon_spacer) + $top_offset);
        }
    }
    imagepng($img); // output the image
    imagedestroy($img); // free the memory used
    ?>
    Now how exactly did you want to watermark it? (Text or an image).

  • #15
    New Coder
    Join Date
    Feb 2007
    Posts
    21
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Thumbs up

    Quote Originally Posted by Inigoesdr View Post
    This will generate the hexagons image:
    PHP Code:
    <?php

    // Misc. Settings
    $hexagon_width 30;
    $hexagon_height 25;
    $hexagon_spacer 3;
    $hexagon_columns 5;
    $hexagon_rows 5;

    header("Content-type: image/png"); // send PNG header
    $img imagecreate(150,175); // create the image pointer
    imagecolorallocate($img,255,255,255); // set the background color
    $color imagecolorallocate($img,255,128,0); // set the hexagon color

    // Custom function to (hopefully) allow scaling of hexagon shapes
    function create_hexagon($img$color$height 25$width 30$left_offset 0$top_offset 0)
    {
        
    $points = array($left_offset,($height 2) + $top_offset// point 1 (left)
                        
    (($width 1) + $left_offset),$top_offset// point 2 (left-top)
                        
    (($width 3) + $left_offset),$top_offset// point 3 (right-top)
                        
    $width $left_offset,($height 2) + $top_offset// point 4 (right)
                        
    ($width 3) + $left_offset,$height $top_offset// point 5 (right-bottom)
                        
    ($width 1) + $left_offset,$height $top_offset); // point 6 (left-bottom)
        
    imagefilledpolygon($img,$points,6,$color);    
    }

    // Loops for columns & rows of hexagons
    for($i 0$i $hexagon_columns$i++)
    {
        for(
    $j 0$j $hexagon_rows$j++)
        {
            
    $top_offset = ($i 2) == ? ($hexagon_height 2) + $hexagon_spacer 0// Add a topspacer to odd numbered rows so the hexagons interlock
            
    create_hexagon($img$color$hexagon_height$hexagon_width, (($hexagon_width 3) + $hexagon_spacer) * $i$j * ($hexagon_height $hexagon_spacer) + $top_offset);
        }
    }
    imagepng($img); // output the image
    imagedestroy($img); // free the memory used
    ?>
    Now how exactly did you want to watermark it? (Text or an image).
    Thank you very much for your responce I haven't tested the code you provided but I'm sure it works thanks again. Aand about watermarking, image watermaking will be great I mean I want to put all those hexagons on some background.
    Last edited by Sandrix; 03-05-2007 at 06:48 AM.


  •  
    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
    •