Forum Moderators: coopster
<?php
$mysock = getimagesize("Scripts/z500.jpg");
//echo $mysock[0]."<br>";
//echo $mysock[1]."<br>";
print_r($mysock);
//$target = "Scripts/z500.jpg";
function imageResize($width, $height, $target) {
//takes the larger size of the width and height and applies the formula accordingly...this is so this script will work dynamically with any size image
if ($width > $height) {
$percentage = ($target / $width);
} else {
$percentage = ($target / $height);
}
//gets the new value and applies the percentage, then rounds the value
$width = round($width * $percentage);
$height = round($height * $percentage);
//returns the new sizes in html image tag format...this is so you
//can plug this function inside an image tag and just get the
return "width=\"$width\" height=\"$height\"";
}
?>
<table width="100%" border="1" cellspacing="1" cellpadding="2">
<tr>
<td><img src="Scripts/z500.jpg" border="0" /></td>
<td><img src="Scripts/z500.jpg" <?php echo imageResize($mysock[0], $mysock[1], 150); ?></td>
</tr>
</table>
<?php
//================================================================================
// PLEASE DO NOT REMOVE THIS HEADER!
//
// COPYRIGHT NOTICE
// This script is licensed under the GPL
//================================================================================
// This software IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
// OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//================================================================================
// Get extension and return it
$file = isset($_GET["pic"])? $_GET["pic"] : '';
$width = isset($_GET["width"])? (int)$_GET["width"] : 350;
$sold = isset($_GET["sold"])? 1 : 0;
if (!empty($file)) {
$ext = pathinfo($file, PATHINFO_EXTENSION);
header("Content-type: image/$ext");
} else {
exit();
}
function openImage($file)
{
// Get extension and return it
$ext = pathinfo($file, PATHINFO_EXTENSION);
switch(strtolower($ext)) {
case 'jpg':
case 'jpeg':
$im = @imagecreatefromjpeg($file);
break;
case 'gif':
$im = @imagecreatefromgif($file);
break;
case 'png':
$im = @imagecreatefrompng($file);
break;
default:
$im = false;
break;
}
return $im;
}
$im = '';
$im = openImage($file);
if (!empty($im)) {
$old_x = imagesx($im);
$old_y = imagesy($im);
$new_w = (int)$width;
if (($new_w <= 0) or ($new_w > $old_x)) {
$new_w = $old_x;
}
$new_h = ($old_x * ($new_w / $old_x));
if ($old_x > $old_y) {
$thumb_w = $new_w;
$thumb_h = $old_y * ($new_h / $old_x);
}
if ($old_x < $old_y) {
$thumb_w = $old_x * ($new_w / $old_y);
$thumb_h = $new_h;
}
if ($old_x == $old_y) {
$thumb_w = $new_w;
$thumb_h = $new_h;
}
$thumb = imagecreatetruecolor($thumb_w,$thumb_h);
if ($sold == 1) {
$watermark_img = openImage('images/watermark.png');
$watermark_width = imagesx($watermark_img);
$watermark_height = imagesy($watermark_img);
$watermark = imagecreatetruecolor($old_x,$old_y);
imagecopyresampled($watermark,$watermark_img,0,0,0,0,$old_x,$old_y,$watermark_width,$watermark_height);
imagedestroy($watermark_img);
imagecopymerge($im, $watermark, 0, 0, 0, 0, $old_x, $old_y, 30);
imagedestroy($watermark);
}
imagecopyresampled($thumb,$im,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);
//choose which image program to use
switch(strtolower($ext)) {
case 'jpg':
case 'jpeg':
imagejpeg($thumb);
break;
case 'gif':
imagegif($thumb);
break;
case 'png':
imagepng($thumb);
break;
default:
exit();
}
imagedestroy($thumb);
imagedestroy($im);
}
?>