Hello all readers . . . I need your help . . . I have create a class that manipulate jpeg images the source code is the following : <------------------------------------------------------------------> class image_manipulation { private $height; private $width; public $image; public function __construct() { $this->width = 0; $this->height = 0; } public function __destruct() { $this->width = 0; $this->height = 0; } public function setImageSize($img_tmp) { $img_info = getimagesize($img_tmp); $filetype = $img_info['mime']; $this->width = $img_info[0]; $this->height = $img_info[1]; return $this->manipulate_jpeg($img_tmp); } private function manipulate_jpeg($img) { $tmp_img = imagecreatefromjpeg($img); if($this->height > $this->width) { $h = (IMG_LRG_HEIGHT * 100) / $this->height; $newHeight = ($this->height/100) * $h; $newWidth = ($this->width/100) * $h; } else { $h = (IMG_LRG_WIDTH * 100) / $this->width; $newHeight = ($this->height/100) * $h; $newWidth = ($this->width/100) * $h; } $img2 = ImageCreateTrueColor($newWidth, $newHeight); @imagecopyresampled($img2, $tmp_img,0,0,0,0,$newWidth,$newHeight, $this->width, $this->height); $xx = imagesx($img2); $yy = imagesy($img2); $fontSize = 30; $fntWidth = @imagefontwidth($fontSize) * strlen(APP_TITLE); $fntHeight = @imagefontheight($fontSize); $fx = ($xx - $fntWidth) - 10; $fh = ($yy - $fntHeight) - 10; $txtColor = @imagecolorallocate($img2, 255, 255, 255); @imagestring($img2, $fontSize, $fx, $fh, APP_TITLE, $txtColor); $this->image = imagejpeg($img2); return $this->image; } } <------------------------------------------------------------------> Now that i have create this class and test it, it work correctly. The problem is the following. I like to store the image data to MySQL database. I know how to store in the database but when i execute the code the Internet Explorer represent the image and in the database it store only one byte. Why ? ? ? Following the database code : <------------------------------------------------------------------> $image_object = new image_manipulation(); $cnn = @mysql_pconnect(IP, USER, PASSWORD); @mysql_select_db(DATABASE_NAME); $query = "INSERT INTO " . TABLE_NAME . "(img_data) VALUES('" . $image_object->setImageSize(FILE_LOCATION) . "')"; <------------------------------------------------------------------> Thanks a lot . . .
Function setImageSize() returns the return value of manipulateJpeg(). Function manipulateJpeg() returns the return value of imagejpeg(), and imagejpeg() returns a boolean value. That's where the 1 byte in your database comes from. BTW, any particular reason why you want to save the binary in the database as opposed to just storing file names of actual image files?
Thanks a lot for your response . . . Because it's more easy to loose file from file system (wrong file delete for example) and more defecault to backup the images writen in folder. If you have stored for example 2000 images then it's deficault to delete them. In any case there is any way to get the binary data from imagejpeg() to store them into the database ? ? ? Thansk a lot . . .
How? Just save the exact file name and path instead of the binary data, and you can delete it as easy as from the database.
Ok then . . . If you have to backup 20000 images you need a lot of time to complete the backup. So i think it is easyer to have one single file with the database data. In any case Is any way to get the binary data from the image ? ? ? ? Thanks . . .
Backing up large amount of data is always time and resource intensive, regardless of whether you store it in the database or as flat files. For images, there's a good chance that it actually takes more time and resources to do the backup if the images are stored in a database. In any case it is a very bad choice to make your decission based on how easy and fast it is to do your backup process, ignoring the fact that storing binary data in database will hit the database performance as a whole. It's like, you're opening a shop and you choose to make your shop as small as possible to make it easier for you to clean it. If you insist on doing what you want to do, of course you can get the binary data of an image and store it in the database. But it'd be a sin for me to help you with that