Next we define our class: class GallerySizer{ To define a class file, you simply use the keyword class followed by the class name; in our case, GallerySizer. The convention behind class names is to capitalize the first letter of the class name, followed by capitalizing the first letter of every following word without underscores or dashes (ie: GallerySizer and not Gallery_Sizer). The variables we've created are known as member data, when discussing them in terns of Object Oriented Programming (OOP). These variables are global to the class, which will allow any method (function) to access them. They are used throughout the script for various functions, including creating the thumbnail, determining the resizable scale for the new images, creating a random filename for the newly converted images, etc. /***** The method above, getLocation($image), accepts an image as its argument. The image will be passed from the upload form to the method, which will then initialize the $image_file variable to hold the name of the image, and the $image_path variable to hold the path to where the resized image will reside on the server. The loadImage() function above determines the file-type of the current image by splitting the filename into an array, split by the dot (.) in its name, using PHP's explode() function. The end() function simply retrieves the last element in the array. Based on the image type, we call the "imagecreatefromXXXX" function, which, in the case of a JPEG, returns a pointer to a true-color image. This pointer is used later on the code to create our resized and thumbnail images. To ensure that every image uploaded is unique, we retrieve the name of the image (less the extension), and add a random value to the image name. In this case, our getRandom() function will return the current date/time value, which will then be appended to the filename, creating a unique name. [Note]
blog comments powered by Disqus |