No announcement yet.

Back to the GD drawing board; gdImageCreateFromJpeg

  • Filter
  • Time
  • Show
Clear All
new posts

    Back to the GD drawing board; gdImageCreateFromJpeg

    I'm trying to create a few functions to take a user uploaded file, and then recreate it to (a) strip out the EXIF data, (b) shrink it down if it's too large.

    And unfortunately, I'm not having any luck with the gdImageCreateFromJpeg()-type functions.

    Here is what I have:

        <MvASSIGN NAME = "l.file_path"                          VALUE = "{ g.source_path $ l.filename }">
        <MvASSIGN NAME = "l.ext"                                VALUE = "{ Get_Extension( l.filename ) }">
        <p>Filename: <MvEVAL EXPR = "{ l.file_path }"></p>
        <MvIF EXPR = "{ NOT sexists( l.file_path ) }">
            <p>File does not exist</p>
        <p>Extension: <MvEVAL EXPR = "{ l.ext }"></p>
        <MvIF       EXPR = "{ tolower( l.ext ) EQ 'jpg' }">
            <MvASSIGN NAME = "l.image"                          VALUE = "{ gdImageCreateFromJpeg( l.file_path, 'script' ) }" />
        <MvELSEIF   EXPR = "{ tolower( l.ext ) EQ 'jpeg' }">
            <MvASSIGN NAME = "l.image"                          VALUE = "{ gdImageCreateFromJpeg( l.file_path, 'script' ) }" />
        <MvELSEIF   EXPR = "{ tolower( l.ext ) EQ 'png' }">
            <MvASSIGN NAME = "l.image"                          VALUE = "{ gdImageCreateFromPng( l.file_path, 'script' ) }" />
        <MvELSEIF   EXPR = "{ tolower( l.ext ) EQ 'gif' }">
            <MvASSIGN NAME = "l.image"                          VALUE = "{ gdImageCreateFromGif( l.file_path, 'script' ) }" />
        <MvEVAL EXPR = "{ 'Image: ' $ l.image }">
    The l.file_path works; it returns the right path ('/test/graphics/thing/000077274-1396450271.jpg'). The Get_Extension() function works and returns the correct value. But the gdImage functions always return a -1 meaning it cannot find/handle the file.

    Is there something else I'm missing? I tried looking at docs, but the image section is woefully behind.

    Any suggestions?


    Usual disclaimer; this is not for Miva Merchant, so don't say "use this Merchant library" as I cannot. However, if there is something in the LSK that I could use as a starting point, that's cool.

    There are a few image related functions in the lsk, but the way to get this sort of thing working is to look at php examples and port it to miva. I've done a bunch of stuff with the gd library and none of it was easy.

    In your example above, you are trying to display data that does not display. I think you can len(l.image) but you can't eval it. In order to make that image show you need to either base64 encode it and display it inline or export it and display it using the IMG tag. I think l.image is just some sort of pointer to the image data that is useless until it's exported or converted into useful data.
    M.A.D.* since 1997

    *miva application developers


      I'm not trying to show the image, just get the return value so that I know it worked.

      For example, right afterwards, I try:

          <MvASSIGN NAME = "l.width"                              VALUE = "{ gdImageSX( l.image ) }" />
          <MvASSIGN NAME = "l.height"                             VALUE = "{ gdImageSY( l.image ) }" />
      Which also comes back as -1 for both values. As for PHP, it's formatted the same (except for Miva needing to specify 'script' vs 'data'.


        Okay - I figured out the bigger issue; "System library 'GD' is not registered"

        I added it to Mia, but I forgot, Mia no longer saves settings. So I tried editing the 'libraries' entry via RegEdit (the only way that seems to stick) but it's still giving me the same GD error message. I do see it listed in Miva Mia's libraries.

        Running `diagtool.mvc` shows:
        GD Library load failed


          Can't help with miva mia, but I'll mention that issues like that are why I moved from miva mia to running empressa in a vmware virtual machine. It was worth the time figuring out how to do that to have a fully working development environment.
          M.A.D.* since 1997

          *miva application developers


            What version of Mia are you running? 5.33 fixed that issue I believe. You may need to run Mia as an administrator so the registry keys get moved over properly and then you should be able to run it as a normal user.

            Did you restart Mia after you manually modified the registry key? A helpful GD debugging function you could use is gdLastError (I'm guessing that would just tell you the library isn't registered too, but once you get it registered it would be helpful in the future).
            David Carver
            Miva, Inc. | Software Developer


              Currently using version 5.31. I guess I can try upgrading to v5.33.

              And yes, I close Mia, make the change, and then restart. It doesn't seem to help.The gdLastError message is "System library 'GD' is not registered". Running diagtool gives the "Library load failed" error.

              As a backup, I'm downloading ubuntu and VirtualBox. Something to try instead of throwing the laptop across the room :)


                I've uploaded to v5.33, but GD is still failing as "Library load failed". Anyone know where I can get a working version of the GD library?