Again, we make use of GD's imagecreatetruecolor() to create a pointer to a true-colored image. imagecopyresampled($tmp_resize, $this->img, 0, 0, 0, 0, RESIZE_WIDTH, RESIZE_HEIGHT, $this->width, $this->height); We then resize our image to the specified size, passing to it the temporary image pointer, the original image, and the 4 parameters dealing with the co-ordinates and size (similar to the ones passed in the setThumbnail() function. GD has a built-in function to destroy the original image uploaded. We'll use this function once our image has been resized, followed by assigning the value of $tmp_resize, to our resized image object ($this->resize). /***** Because we're not storing our images in a database, we need to copy the file over to our new images to our desired directories, specified in our constant variables. imagejpeg($this->thumb, $this->thumbnail); The imagejpeg() function will actually write the JPEG file information to a file that will now reside in the filesystem. We pass, as arguments, the thumbnail pointer ($this->thumb) and the object which will represent the actual thumbnail file ($this->thumbnail). We then copy the image to our thumbnail directory, set the desired permissions (making use of PHP's chmod() function), and unlink/delete the temporary thumbnail image. /***** Our copyResizedImage() function is identical to the copyThumbImage() function, except that we work with the resized image rather than the thumbnail. /***** Our getRandom() function simply returns a string value with the current date and time with a seconds value. /***** The getThumbLocation() function returns the path to our thumbnail image, so that the value may be inserted into our database for retrieval later on. /***** The getImageLocation() returns the path to our resized image, which will be inserted into our database for retrieval later on.
blog comments powered by Disqus |