if (!$_FILES['product_image']['error']) { //now is the time to modify the future file name and validate the file $new_file_name = strtolower($_FILES['product_image']['tmp_name']); //rename file if ($_FILES['product_image']['size'] > 2024000) { $valid_file = false; $message = 'Oops! Your file\'s size is to large.'; echo $message; } else { $valid_file = true; } //if the file has passed the test if ($valid_file) { //move it to where we want it to be $WaterMark = '../../images/watermark.gif'; watermarkImage($_FILES['product_image']['tmp_name'], $WaterMark, $_FILES['product_image']['tmp_name'], 50); $currentdir = getcwd(); $target = '../../images/' . basename($_FILES['product_image']['name']); move_uploaded_file($_FILES['product_image']['tmp_name'], $target); $message = 'Congratulations! Your file was accepted.'; echo $message; } } else { //set that to be the returned message $message = 'Ooops! Your upload triggered the following error: ' . $_FILES['product_image']['error']; echo $message; } } //you get the following information for each file: // $_FILES['field_name']['name'] // $_FILES['field_name']['size']
} if (!hotlink()) { if (!$debug_img) { header('Content-type: image/' . $img['ext']); } // donwload image header if ($img['type'] == 4) { header('Content-Length: ' . $image['size']); header('Content-Disposition: attachment;filename="' . $image['name'] . '"'); } readfile($img_address); $img['type'] = 4; } else { not_max_bandwidth($image, $img['type']); if ($settings['SET_WATERMARK']) { watermarkImage($img_address); } else { if (!$debug_img) { header('Content-type: image/' . $img['ext']); } readfile($img_address); } } } else { if (!$debug_img) { header('Content-type: image/png'); } readfile('img/notfound.png'); } if ($img['type'] != 4) { // flushNow(1);
<?php function watermarkImage($SourceFile, $WaterMarkText, $DestinationFile) { list($width, $height) = getimagesize($SourceFile); $image_p = imagecreatetruecolor($width, $height); $image = imagecreatefromjpeg($SourceFile); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width, $height); $black = imagecolorallocate($image_p, 0, 0, 0); $font = '/var/www/html/samples/php/watermark/case6/arial.ttf'; $font_size = 10; imagettftext($image_p, $font_size, 0, 10, 20, $black, $font, $WaterMarkText); if ($DestinationFile != '') { imagejpeg($image_p, $DestinationFile, 100); } else { header('Content-Type: image/jpeg'); imagejpeg($image_p, null, 100); } imagedestroy($image); imagedestroy($image_p); } $SourceFile = '/var/www/html/samples/php/watermark/case6/logo/csi.jpg'; $DestinationFile = '/var/www/html/samples/php/watermark/case6/logo/csi.jpg'; $WaterMarkText = 'Copyright phpJabbers.com'; watermarkImage($SourceFile, $WaterMarkText, $DestinationFile);
$isJPEG = in_array(strtolower($ext), $display); $isThumb = False; $aSize = count($parts); if ($aSize > 0) { $isThumb = $parts[$aSize - 1] == 'thumb'; } return $isJPEG && !$isThumb; } set_time_limit(0); $watermark = imagecreatefrompng('../images/watermark.png'); $it = new RecursiveDirectoryIterator("../images"); foreach (new RecursiveIteratorIterator($it) as $file) { if (isTargetImage($file)) { setImageCopyright($file, 'Copyright 2014 Emel Hamlet'); $image = imagecreatefromjpeg($file); if (strpos($file, '../images/current') === 0 || strpos($file, '../images/past') === 0) { $parts = explode('.', $file); $ext = array_pop($parts); array_push($parts, 'thumb', $ext); $thumbnail = implode('.', $parts); resizeImage($image, NULL, 500); watermarkImage($image, $watermark); createThumbnail($image, $thumbnail, NULL, 150); } else { watermarkImage($image, $watermark); } imagejpeg($image, getcwd() . '/' . $file); imagedestroy($image); } } imagedestroy($watermark);