Resizing uploaded images before inserting as BLOB

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mat

    Resizing uploaded images before inserting as BLOB

    Hi,
    I have a system that uploads images as BLOBs in a database. I also
    have a function that I use to resize uploaded images before saving as
    files. I would like to combine these two by resising the images before
    inserting them as BLOBs.
    My problem is that (apart from being new to file stuff) my resize
    function returns a Resource ID which of course is not the same as the
    file handler that was passed to it, it's a reference to an image
    created with imagecreate(). The resize function usually uses
    imagejpeg() for the final step of creating the file, is there
    something similar I need to use to return a file reference for
    inserting into the database?

    This is the bit that inserts the resized image into the database..

    $thisImage = createImageFrom Source($fm_imag e,"",$imgWidth, $imgHeight,"low ");
    if($thisImage){
    $imageData = addslashes(frea d(fopen($thisIm age, "r"),
    filesize($thisI mage)));
    doQuery("INSERT into
    productImages(f ileData,fileSiz e,fileType,prod uctID)
    VALUES('".$imag eData."','".$th isImage_size."' ,'".$thisImage_ type."','".$fm_ productID."');" );
    }

    As you can see, I need createImageFrom Source() to return a file
    handler into $thisImage that can be used by the fread and fopen
    functions. At present createImageFrom Source does this (GD 1.6.2):

    $src = imagecreatefrom jpeg($source);
    $dst = imagecreate($tn _width,$tn_heig ht);
    imagecopyresize d($dst, $src, 0,0,0,0, $tn_width, $tn_height, $width,
    $height);
    if($destination !=""){
    imagejpeg($dst, $destination, -1);
    }else{
    return $dst;
    }

    So if there is no $destination path, it just returns the reference,
    what can I do here to return what I need? Is it possible?

    Thanks for your help,
    Mat
  • Uzi Klein

    #2
    Re: Resizing uploaded images before inserting as BLOB

    I would put that in the "not a very good idea" section....
    why would you put your file in the database?
    just store the file in a dir on the server and store the path in the DB....


    "Mat" <google@matthew marlow.com> wrote in message news:846bb688.0 405090150.6c083 a82@posting.goo gle.com...[color=blue]
    > Hi,
    > I have a system that uploads images as BLOBs in a database. I also
    > have a function that I use to resize uploaded images before saving as
    > files. I would like to combine these two by resising the images before
    > inserting them as BLOBs.
    > My problem is that (apart from being new to file stuff) my resize
    > function returns a Resource ID which of course is not the same as the
    > file handler that was passed to it, it's a reference to an image
    > created with imagecreate(). The resize function usually uses
    > imagejpeg() for the final step of creating the file, is there
    > something similar I need to use to return a file reference for
    > inserting into the database?
    >
    > This is the bit that inserts the resized image into the database..
    >
    > $thisImage = createImageFrom Source($fm_imag e,"",$imgWidth, $imgHeight,"low ");
    > if($thisImage){
    > $imageData = addslashes(frea d(fopen($thisIm age, "r"),
    > filesize($thisI mage)));
    > doQuery("INSERT into
    > productImages(f ileData,fileSiz e,fileType,prod uctID)
    > VALUES('".$imag eData."','".$th isImage_size."' ,'".$thisImage_ type."','".$fm_ productID."');" );
    > }
    >
    > As you can see, I need createImageFrom Source() to return a file
    > handler into $thisImage that can be used by the fread and fopen
    > functions. At present createImageFrom Source does this (GD 1.6.2):
    >
    > $src = imagecreatefrom jpeg($source);
    > $dst = imagecreate($tn _width,$tn_heig ht);
    > imagecopyresize d($dst, $src, 0,0,0,0, $tn_width, $tn_height, $width,
    > $height);
    > if($destination !=""){
    > imagejpeg($dst, $destination, -1);
    > }else{
    > return $dst;
    > }
    >
    > So if there is no $destination path, it just returns the reference,
    > what can I do here to return what I need? Is it possible?
    >
    > Thanks for your help,
    > Mat[/color]


    Comment

    Working...