Announcement

Collapse
No announcement yet.

GD Examples?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    GD Examples?

    I'm trying to play with the GD library. I downloaded the latest GD library and pointed Mia to the bgd.dll. I then whipped up this little script:

    Code:
    <MIVA STANDARDOUTPUTLEVEL="">
    <MvASSIGN NAME = "l.null" VALUE = "{ miva_output_header('Content-type','image/png' ) }">
    <MvASSIGN NAME = "l.x_size"			VALUE = "{ 200 }">
    <MvASSIGN NAME = "l.y_size"			VALUE = "{ 100 }">
    <MvASSIGN NAME = "l.image"			VALUE = "{ gdImageCreateTrueColor( l.x_size, l.y_size ) }">
    <MvASSIGN NAME = "l.black"			VALUE = "{ gdImageColorAllocate( l.image, 0, 0, 0 ) }">
    <MvASSIGN NAME = "l.green"			VALUE = "{ gdImageColorAllocate( l.image, 0, 0, 255 ) }">
    <MvASSIGN NAME = "l.red"			VALUE = "{ gdImageColorAllocate( l.image, 255, 0, 0 ) }">
    <MvASSIGN NAME = "l.white"			VALUE = "{ gdImageColorAllocate( l.image, 255, 255, 255 ) }">
    <MvASSIGN NAME = "l.fill1"			VALUE = "{ gdImageFilledRectangle( l.image, 10, 10, 80, 80, l.red ) }">
    <MvASSIGN NAME = "l.draw"			VALUE = "{ gdImagePng( l.image, 'square.png', '/' ) }">
    <MvASSIGN NAME = "l.destroy"		VALUE = "{ gdImageDestroy( l.image ) }">
    <MvASSIGN NAME = "l.error"			VALUE = "{ gdLastError() }">
    <MvEXPORT FILE = "error.txt" FIELDS = "l.image, l.black, l.white, l.red, l.green, l.fill1, l.draw, l.destroy, l.error" DELIMITER = "|">
    <MvEXIT>
    But no image shows up.

    The error.txt doesn't show anything useful
    1|0|16777215|16711680|255||||

    Looks like the ImageCreate works, the colors are assigned a hue value, and then nothing else happens.

    What's missing?

    Thanks

    #2
    Re: GD Examples?

    The "location" parameter to gdImagePng should be one of "script" or "data", not "/".

    At first glance that example looks fine, and it should have generated a file called square.png in your data directory. Did it?

    Comment


      #3
      Re: GD Examples?

      If I changed the location to "data" (and remove the Destroy statement) it will create the image in the data directory.

      "script" will default to create it in the same directory as the script being run; need to remember to start with '/'

      If location is blank, then it defaults to the data directory.

      If I include the Destroy command then I do not see a png file. Probably made and deleted too quick to even see.

      If I remove the filename, I get an error in my export log:
      "Unable to create output file: Access is denied.\r\n"

      I would think that without a name it should just display in the browser.
      Last edited by Scott McCollough; 06-30-10, 02:40 PM.

      Comment


        #4
        Re: GD Examples?

        Hi folks -- this is news to me. Where do I get a copy of this library, and how do I install it? Can it be used on servers, as well as under Mia?

        Thanks --
        Kent Multer
        Magic Metal Productions
        http://TheMagicM.com
        * Web developer/designer
        * E-commerce and Miva
        * Author, The Official Miva Web Scripting Book -- available on-line:
        http://www.amazon.com/exec/obidos/IS...icmetalproducA

        Comment


          #5
          Re: GD Examples?

          Many servers already have it installed. If you need to get the latest release, go to http://www.libgd.org/releases/

          For Mia, unzip the gd-latest-win32.zip file to a known location. Go to Mia's configuration page, and click on "Libraries".

          Add a new "System" type, call it "gd" (Although I don't know if it matters), and point it to the %unzip path%\bin\bgd.dll file. Click OK OK OK and you should be good to go.

          I have not tried installing to IIS or Linux but I'm sure there is documentation out there for those.

          So... How do we use gdImage to display an image, instead of saving? I really want to use:

          Code:
          <img src="{ Draw_Graph( l.stats ) }" id="graph" />
          Instead of making a tangible item, display it, and delete it.

          Thanks

          Comment


            #6
            Re: GD Examples?

            Is there any documentation?

            Thanks --
            Kent Multer
            Magic Metal Productions
            http://TheMagicM.com
            * Web developer/designer
            * E-commerce and Miva
            * Author, The Official Miva Web Scripting Book -- available on-line:
            http://www.amazon.com/exec/obidos/IS...icmetalproducA

            Comment


              #7
              Re: GD Examples?

              Originally posted by Kent Multer View Post
              Hi folks -- this is news to me. Where do I get a copy of this library, and how do I install it? Can it be used on servers, as well as under Mia?

              Thanks --
              Hi Kent,

              Look at Empresa 5.7! Christmas in Mivaland!

              Markus
              Emerald Media, Trade & Technology USA/Germany
              Professional Miva Programming since 1998
              Home of the Emerald Objects Application Server (EOA)
              Multi-dimensional CRM, CMS & E-Commerce

              http://www.emeraldobjects.com
              http://www.sylter-seiten.com

              Comment


                #8
                Re: GD Examples?

                Originally posted by Kent Multer View Post
                Hi folks -- this is news to me. Where do I get a copy of this library, and how do I install it? Can it be used on servers, as well as under Mia?

                Thanks --
                Go to that same URL, and download the appropriate zip file. They include installation instructions.

                I'm still trying to figure out how to display an image inline without having to create an actual file.

                Burch?

                Comment


                  #9
                  Re: GD Examples?

                  Burch is on vacation until Tuesday, I'm sure he'll reply then.
                  Thanks,

                  Rick Wilson
                  CEO
                  Miva, Inc.
                  [email protected]
                  https://www.miva.com

                  Comment


                    #10
                    Re: GD Examples?

                    Hope everyone had a good holiday/vacation.

                    Do we have an answer to this one yet? How can we display a dynamically created image without first making a file?

                    Thanks

                    Comment


                      #11
                      Re: GD Examples?

                      You cannot.

                      Comment


                        #12
                        Re: GD Examples?

                        you have to have the correct 'headers' associated with the output of the script, because since there isn't an actual physical file being called, you don't have apache (or the operating system) supplying the headers for the file based on it's file type... you have to do it in place of what the os would do.

                        It's the same as if you kept the image stored in a binary field in a database.

                        least I"m pretty sure.. that's what I have to do in php anyway. in that way it's possible to not create an actual physical file on the hard drive.

                        I'm not sure why you'd want to create such an ephemeral file anyway.
                        If you're making thumbnails... it would be way way way better on future page loading if you create a physical file. Then check for the presense of the file before you create another copy of it. . Sure would save cpu usage and thus your site could support way more simultaneous users.
                        Last edited by kayakbabe; 07-12-10, 09:33 AM.

                        Comment


                          #13
                          Re: GD Examples?

                          Here's an example from the php library that might help you.
                          http://www.php.net/manual/en/image.examples-png.php
                          It makes a button using an existing image file and the word 'text' which is passed to it, then deletes the image out of server memory so you don't get a memory leak from using the script.

                          You'll have to translate that to mivascript
                          You would call this image by having an image html code like
                          <img src='filename.php?text=text'>

                          notice how the coder puts the header into the output.. that let's the browser know what is coming next is a png image.

                          <?php

                          header
                          ("Content-type: image/png");
                          $string = $_GET['text'];
                          $im = imagecreatefrompng("images/button1.png");
                          $orange = imagecolorallocate($im, 220, 210, 60);
                          $px = (imagesx($im) - 7.5 * strlen($string)) / 2;
                          imagestring($im, 3, $px, 9, $string, $orange);
                          imagepng($im);
                          imagedestroy($im);

                          ?>

                          I would suggest that you do some strict validation of the data passed into your image creating script too.
                          it can't be too big a hop to
                          <img src='filename.mvc?text=text'>

                          (note: i didn't test the above script, but it was the basis for my own which works)
                          Last edited by kayakbabe; 07-12-10, 09:54 AM.

                          Comment


                            #14
                            Re: GD Examples?

                            Originally posted by kayakbabe View Post
                            Here's an example from the php library that might help you.
                            http://www.php.net/manual/en/image.examples-png.php
                            It makes a button using an existing image file and the word 'text' which is passed to it, then deletes the image out of server memory so you don't get a memory leak from using the script.

                            You'll have to translate that to mivascript
                            You would call this image by having an image html code like
                            <img src='filename.php?text=text'>

                            notice how the coder puts the header into the output.. that let's the browser know what is coming next is a png image.

                            <?php

                            header
                            ("Content-type: image/png");
                            $string = $_GET['text'];
                            $im = imagecreatefrompng("images/button1.png");
                            $orange = imagecolorallocate($im, 220, 210, 60);
                            $px = (imagesx($im) - 7.5 * strlen($string)) / 2;
                            imagestring($im, 3, $px, 9, $string, $orange);
                            imagepng($im);
                            imagedestroy($im);

                            ?>

                            I would suggest that you do some strict validation of the data passed into your image creating script too.
                            it can't be too big a hop to
                            <img src='filename.mvc?text=text'>

                            (note: i didn't test the above script, but it was the basis for my own which works)
                            If you look at the first post of the thread, you can see that is what I'm trying to accomplish. Well, not editing an existing image, but making one from scratch. Still, the concept is the same--imagepng should be capable of creating an image in memory, not require saving it to the hard drive.

                            My ideal would be something like
                            Code:
                            <img src="{ [g.image_library].Draw_BarChart( l.chart_array ) }" />
                            So the g.image_library file automatically sets the header to PNG, and takes the data from the passed array and draws a bar chart.

                            To accomplish this now would require:
                            -Passing the array to Draw_BarChart
                            -Finding a unique filename (to prevent overwriting, file lock issues, race conditions, etc)
                            -Display the file
                            -Delete the file

                            This means constant disk thrash from the creation and deletion of a 1-5k file for each user of the website. Assuming you want dynamic.

                            I would like the team to consider adding this ability when they release 5.08. By not being able to create on the fly images, it really limits the functionality of this new and much needed feature.

                            Thanks
                            Last edited by Scott McCollough; 07-12-10, 12:02 PM.

                            Comment


                              #15
                              Re: GD Examples?

                              We will consider adding in-memory output at some point in the future, but I can't promise it for 5.08.

                              In the meantime, you should be able to use gdImageJpeg() to output a file to the data directory, read its contents using file_read() and then delete the temporary file to accomplish what you want to do.

                              Comment

                              Working...
                              X