Specifications

The key to the resize operation is the calculation of the new width and height parameters. We
find the ratio between the actual and maximum dimensions. $max_width and $max_height can
be passed in on the query string; otherwise, the default values specified at the top of the listing
will be used.
$x_ratio = $max_width / $width;
$y_ratio = $max_height / $height;
If the image is already smaller than the specified maximum dimensions, the width and height
are left unchanged. Otherwise, either the X or Y ratio is then used to scale both dimensions
equally so that the reduced size image is not stretched or squashed, as follows:
if ( ($width <= $max_width) && ($height <= $max_height) ) {
$tn_width = $width;
$tn_height = $height;
}
else if (($x_ratio * $height) < $max_height) {
$tn_height = ceil($x_ratio * $height);
$tn_width = $max_width;
}
else {
$tn_width = ceil($y_ratio * $width);
$tn_height = $max_height;
}
Solution Design/Overview
A summary of the files in this application is shown in Table 26.1.
TABLE 26.1 Files in the Content Management Application
Name Type Description
create_database.sql SQL SQL to set up the content database and some
sample data
include_fns.php Functions Collection of include files for this application
db_fns.php Functions Collection of functions for connecting to con-
tent database
select_fns.php Functions Collection of functions to aid creation of
SELECT lists
user_auth_fns.php Functions Collection of functions for authenticating
users
header.php Template Shown at the top of every content page
footer.php Template Shown at the bottom of every content page
Building a Content Management System
C
HAPTER 26
26
CONTENT
MANAGEMENT
SYSTEMS
595
32 7842 ch26 3/6/01 3:36 PM Page 595