slpctrl Posted May 4, 2008 Share Posted May 4, 2008 <?php //begin function function sizemark($image, $w, $h) { header("Content-type: image/jpeg"); $image = $_GET['image']; $w = $_GET['w']; $h = $_GET['h']; $x = @getimagesize($image); $sw = $x[0]; $sh = $x[1]; $new = @ImageCreateFromJPEG($image) or $new = @ImageCreateFromPNG($image) or $new = @ImageCreateFromGIF($image) or $new = false; if(!$new) { readfile($new); } else { $thumb = @ImageCreateTrueColor($w, $h); @ImageCopyResampled($thumb, $new, 0, 0, 0, 0, $w, $h, $sw, $sh); $image = $thumb; $watermark = imagecreatefrompng('watermark.png'); $watermark_width = imagesx($watermark); $watermark_height = imagesy($watermark); $dest_x = (imagesx($image) - $watermark_width)/2; $dest_y = (imagesy($image) - $watermark_height)/2; imagecopymerge($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, 30); imagejpeg($image); imagedestroy($image); imagedestroy($watermark); return $image; } return false; } //end function $image = $_GET['image']; $width = $_GET['w']; $height = $_GET['h']; if(isset($image) && isset($width) && isset($height) && !empty($image) && !empty($width) && !empty($height)) sizemark($image,$width,$height); else die(); ?> This script works, but what if I wanted to set the default value of the image to say 320x240? I know in theory it should be easy, but in the function it's looking for the GET values, not anything hard coded from the function so I can't figure out how to make a default. Here was my attempt, but it doesn't work: <?php //begin function function sizemark($image, $w, $h) { header("Content-type: image/jpeg"); $image = $_GET['image']; $w = $_GET['w']; $h = $_GET['h']; $x = @getimagesize($image); $sw = $x[0]; $sh = $x[1]; $new = @ImageCreateFromJPEG($image) or $new = @ImageCreateFromPNG($image) or $new = @ImageCreateFromGIF($image) or $new = false; if(!$new) { readfile($new); } else { $thumb = @ImageCreateTrueColor($w, $h); @ImageCopyResampled($thumb, $new, 0, 0, 0, 0, $w, $h, $sw, $sh); $image = $thumb; $watermark = imagecreatefrompng('watermark.png'); $watermark_width = imagesx($watermark); $watermark_height = imagesy($watermark); $dest_x = (imagesx($image) - $watermark_width)/2; $dest_y = (imagesy($image) - $watermark_height)/2; imagecopymerge($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, 30); imagejpeg($image); imagedestroy($image); imagedestroy($watermark); return $image; } return false; } //end function $image = $_GET['image']; $width = $_GET['w']; $height = $_GET['h']; if(isset($image) && isset($width) && isset($height) && !empty($image) && !empty($width) && !empty($height)) sizemark($image,$width,$height); elseif (isset($image) && empty($width) && empty($height)) sizemark($image,320,240); else die(); ?> Link to comment https://forums.phpfreaks.com/topic/104016-another-quick-question/ Share on other sites More sharing options...
blueman378 Posted May 4, 2008 Share Posted May 4, 2008 hi there jsut change $w = $_GET['w']; $h = $_GET['h']; to $w = "320"; $h = "240"; Link to comment https://forums.phpfreaks.com/topic/104016-another-quick-question/#findComment-532500 Share on other sites More sharing options...
slpctrl Posted May 4, 2008 Author Share Posted May 4, 2008 hi there jsut change $w = $_GET['w']; $h = $_GET['h']; to $w = "320"; $h = "240"; But that would hard code the entire thing. I want the option of giving it any dimension I want, but if a dimension isn't given I want that dimension to be assigned those values. Link to comment https://forums.phpfreaks.com/topic/104016-another-quick-question/#findComment-532502 Share on other sites More sharing options...
trq Posted May 4, 2008 Share Posted May 4, 2008 Then simply use an if statement. <?php if (isset($_GET['w']) && isset($_GET['h'])) { $w = $_GET['w']; $h = $_GET['h']; } else { $w = 320; $h = 240; } ?> Link to comment https://forums.phpfreaks.com/topic/104016-another-quick-question/#findComment-532505 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.