FAQ
Hello :)
I am working on a little project with MongoDB(V.1.3 driver), PHP 5 and the
GD Graphics Library for university.
At the moment, the User can upload an Image(jpg-File) to my MongoDB
GridFS...this works very good! But i have 2 Problems :/
The first Problem is, the upload Image must be resize before i save it to
my GridFs :/ Our Professor told us, we have to use the GD Library from PHP
but i
dont found anyway to save the resized File back to my Gridfs.
The second Problem is, i found no way to get files out of my gridFS
Collection, modify for example the size,color,brightness and soon with PHP
GD Methods and save it back to the Grid :/

Have anybody an Idea, how i can realize that ?

kind regards :)

Podux

--
You received this message because you are subscribed to the Google
Groups "mongodb-user" group.
To post to this group, send email to mongodb-user@googlegroups.com
To unsubscribe from this group, send email to
mongodb-user+unsubscribe@googlegroups.com
See also the IRC channel -- freenode.net#mongodb

Search Discussions

  • Sam Millman at Nov 25, 2012 at 11:40 am
    Since this is homework you must understand I won't give you the answer
    directly.

    A good place to start is with the documentation on gridfs:
    http://www.php.net/manual/en/mongo.gridfs.php

    Gridfs works a lot like a normal collection when using the helper class. If
    you look on this page:
    http://www.php.net/manual/en/class.mongogridfs.phpyou will see this
    example:

    <?php

    // save a file
    $id = $grid->storeFile("game.tgz");
    $game = $grid->findOne();

    // add a downloads counter
    $game->file['downloads'] = 0;
    $grid->save($game->file);

    // increment the counter
    $grid->update(array("_id" => $id), array('$inc' => array("downloads" => 1
    )));

    ?>

    That goes close to what you need but you will need to access the
    http://www.php.net/manual/en/class.mongogridfsfile.php ($game in the
    example) and then use imagecreatefromstring() or a pre-built image library
    to do the work for you. Once done you can use
    http://www.php.net/manual/en/mongogridfsfile.write.php on the $game
    variable to write back the data into gridfs.

    That should get you started.


    On 25 November 2012 09:37, Podux wrote:

    Hello :)
    I am working on a little project with MongoDB(V.1.3 driver), PHP 5 and the
    GD Graphics Library for university.
    At the moment, the User can upload an Image(jpg-File) to my MongoDB
    GridFS...this works very good! But i have 2 Problems :/
    The first Problem is, the upload Image must be resize before i save it to
    my GridFs :/ Our Professor told us, we have to use the GD Library from PHP
    but i
    dont found anyway to save the resized File back to my Gridfs.
    The second Problem is, i found no way to get files out of my gridFS
    Collection, modify for example the size,color,brightness and soon with PHP
    GD Methods and save it back to the Grid :/

    Have anybody an Idea, how i can realize that ?

    kind regards :)

    Podux

    --
    You received this message because you are subscribed to the Google
    Groups "mongodb-user" group.
    To post to this group, send email to mongodb-user@googlegroups.com
    To unsubscribe from this group, send email to
    mongodb-user+unsubscribe@googlegroups.com
    See also the IRC channel -- freenode.net#mongodb
    --
    You received this message because you are subscribed to the Google
    Groups "mongodb-user" group.
    To post to this group, send email to mongodb-user@googlegroups.com
    To unsubscribe from this group, send email to
    mongodb-user+unsubscribe@googlegroups.com
    See also the IRC channel -- freenode.net#mongodb
  • Podux at Nov 25, 2012 at 6:40 pm
    At first much thanks for your answer. It was really usefull!


    $grid = Database::getGridCollection('bilder');
    $doc = $grid->findOne($_GET['getdbimage']);
    $image_p = imagecreatetruecolor(500, 500);
    $image = imagecreatefromstring($doc->getBytes());
    imagecopyresampled($image_p, $image, 0, 0, 0, 0, 100, 100, 100, 100);

    I found no way to write the new $image_p back to the MongoDb :/

    $doc -> write() is no option, because it is not allowed for us to write
    files to HDD

    $grid->storeBytes(???); I would use this function, but i found no GD method
    the convert the image_p to an Byte Stream.(The same prob at the storeFile
    Function)

    --
    You received this message because you are subscribed to the Google
    Groups "mongodb-user" group.
    To post to this group, send email to mongodb-user@googlegroups.com
    To unsubscribe from this group, send email to
    mongodb-user+unsubscribe@googlegroups.com
    See also the IRC channel -- freenode.net#mongodb
  • Derick Rethans at Nov 26, 2012 at 11:58 am

    On Sun, 25 Nov 2012, Podux wrote:

    At first much thanks for your answer. It was really usefull!

    $grid = Database::getGridCollection('bilder');
    $doc = $grid->findOne($_GET['getdbimage']);
    $image_p = imagecreatetruecolor(500, 500);
    $image = imagecreatefromstring($doc->getBytes());
    imagecopyresampled($image_p, $image, 0, 0, 0, 0, 100, 100, 100, 100);

    I found no way to write the new $image_p back to the MongoDb :/

    $doc -> write() is no option, because it is not allowed for us to write
    files to HDD

    $grid->storeBytes(???); I would use this function, but i found no GD method
    the convert the image_p to an Byte Stream.(The same prob at the storeFile
    Function)
    You can actually do that, in imagepng's doc
    (http://uk1.php.net/manual/en/function.imagepng.php) it says "The path
    to save the file to. If not set or NULL, the raw image stream will be
    outputted directly." - if you combine that with output buffering, you
    can capture that output, and then use storeBytes() again. Output
    buffering is also well documented in the PHP manual.

    cheers,
    Derick

    --
    {
    website: [ "http://mongodb.org", "http://derickrethans.nl" ],
    twitter: [ "@derickr", "@mongodb" ]
    }

    --
    You received this message because you are subscribed to the Google
    Groups "mongodb-user" group.
    To post to this group, send email to mongodb-user@googlegroups.com
    To unsubscribe from this group, send email to
    mongodb-user+unsubscribe@googlegroups.com
    See also the IRC channel -- freenode.net#mongodb

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupmongodb-user @
categoriesmongodb
postedNov 25, '12 at 10:51a
activeNov 26, '12 at 11:58a
posts4
users3
websitemongodb.org
irc#mongodb

People

Translate

site design / logo © 2022 Grokbase