I have a PHP file that creates a watermark on ALL images in a specified folder. How can I modify this so that it only creates watermarks on images whos filenames start with a number but not with images whos filenames start with a letter? <? /* activeWatermark Free script that places watermark on images in folder Copyright (C) 2005 ActiveUnit.com This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // IMAGE WATERMARK (comment line below if you do not want to use image watermark) // Define('WATERMARK_IMAGE', './wt.png'); // path to watermark image // Define('WATERMARK_PERCENT', '60'); // Intensity of the transition (in percent) // TEXT WATERMARK (comment line below if you do not want to use text) Define('WATERMARK_TEXT', 'Watermark Text'); // text to place (image will not be used) Define('WATERMARK_TEXT_FONT', '2'); // font 1 / 2 / 3 / 4 / 5 Define('TEXT_SHADOW', '0'); // 1 - yes / 0 - no Define('TEXT_COLOR', '#000000'); // text color // GENERAL SETTINGS Define('WATERMARK_ALIGN_H', 'right'); // left / right / center Define('WATERMARK_ALIGN_V', 'bottom'); // top / bottom / center Define('WATERMARK_MARGIN', '10'); // margin // ---------------------------------------------------------------------------------------- $dr=preg_replace('/modify\.php.+/', '', $_SERVER['PHP_SELF']); $filename=str_replace($dr, './', $_SERVER['PATH_INFO']); $lst=GetImageSize($filename); $image_width=$lst[0]; $image_height=$lst[1]; $image_format=$lst[2]; if ($image_format==1) { Header("Content-Type:image/gif"); readfile($filename); exit; } elseif ($image_format==2) { $old_image=imagecreatefromjpeg($filename); } elseif ($image_format==3) { $old_image=imagecreatefrompng($filename); } else { readfile($filename); exit; } if (Defined('WATERMARK_TEXT') && WATERMARK_TEXT!='') { // text $color = eregi_replace("#","", TEXT_COLOR); $red = hexdec(substr($color,0,2)); $green = hexdec(substr($color,2,2)); $blue = hexdec(substr($color,4,2)); $text_color = imagecolorallocate ($old_image, $red, $green, $blue); $text_height=imagefontheight(WATERMARK_TEXT_FONT); $text_width=strlen(WATERMARK_TEXT)*imagefontwidth(WATERMARK_TEXT_FONT); $wt_y=WATERMARK_MARGIN; if (WATERMARK_ALIGN_V=='top') { $wt_y=WATERMARK_MARGIN; } elseif (WATERMARK_ALIGN_V=='bottom') { $wt_y=$image_height-$text_height-WATERMARK_MARGIN; } elseif (WATERMARK_ALIGN_V=='center') { $wt_y=(int)($image_height/2-$text_height/2); } $wt_x=WATERMARK_MARGIN; if (WATERMARK_ALIGN_H=='left') { $wt_x=WATERMARK_MARGIN; } elseif (WATERMARK_ALIGN_H=='right') { $wt_x=$image_width-$text_width-WATERMARK_MARGIN; } elseif (WATERMARK_ALIGN_H=='center') { $wt_x=(int)($image_width/2-$text_width/2); } if (TEXT_SHADOW=='1') { imagestring($old_image, WATERMARK_TEXT_FONT, $wt_x+1, $wt_y+1, WATERMARK_TEXT, 0); } imagestring($old_image, WATERMARK_TEXT_FONT, $wt_x, $wt_y, WATERMARK_TEXT, $text_color); } if (Defined('WATERMARK_IMAGE') && WATERMARK_IMAGE!='' && file_exists(WATERMARK_IMAGE)) { // image $lst2=GetImageSize(WATERMARK_IMAGE); $image2_width=$lst2[0]; $image2_height=$lst2[1]; $image2_format=$lst2[2]; if ($image2_format==2) { $wt_image=imagecreatefromjpeg(WATERMARK_IMAGE); } elseif ($image2_format==3) { $wt_image=imagecreatefrompng(WATERMARK_IMAGE); } if ($wt_image) { $wt_y=WATERMARK_MARGIN; if (WATERMARK_ALIGN_V=='top') { $wt_y=WATERMARK_MARGIN; } elseif (WATERMARK_ALIGN_V=='bottom') { $wt_y=$image_height-$image2_height-WATERMARK_MARGIN; } elseif (WATERMARK_ALIGN_V=='center') { $wt_y=(int)($image_height/2-$image2_height/2); } $wt_x=WATERMARK_MARGIN; if (WATERMARK_ALIGN_H=='left') { $wt_x=WATERMARK_MARGIN; } elseif (WATERMARK_ALIGN_H=='right') { $wt_x=$image_width-$image2_width-WATERMARK_MARGIN; } elseif (WATERMARK_ALIGN_H=='center') { $wt_x=(int)($image_width/2-$image2_width/2); } imagecopymerge($old_image, $wt_image, $wt_x, $wt_y, 0, 0, $image2_width, $image2_height, WATERMARK_PERCENT); } } if ($image_format==2) { imageJpeg($old_image); } if ($image_format==3) { imagePng($old_image); } ?> PHP:
Put something like this under: $filename=str_replace($dr, './', $_SERVER['PATH_INFO']); PHP: if (!in_array(substr($filename, 0, 1), range(0, 9))){ readfile($filename); exit; } PHP: Anything that doesn't begin with a number won't be processed. Jay
hey jayshah that didnt change anything... Its still watermaking the images with filenames s3.jpg for example
<? /* activeWatermark Free script that places watermark on images in folder Copyright (C) 2005 ActiveUnit.com This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // IMAGE WATERMARK (comment line below if you do not want to use image watermark) // Define('WATERMARK_IMAGE', './wt.png'); // path to watermark image // Define('WATERMARK_PERCENT', '60'); // Intensity of the transition (in percent) // TEXT WATERMARK (comment line below if you do not want to use text) Define('WATERMARK_TEXT', 'TEXT'); // text to place (image will not be used) Define('WATERMARK_TEXT_FONT', '2'); // font 1 / 2 / 3 / 4 / 5 Define('TEXT_SHADOW', '0'); // 1 - yes / 0 - no Define('TEXT_COLOR', '#000000'); // text color // GENERAL SETTINGS Define('WATERMARK_ALIGN_H', 'right'); // left / right / center Define('WATERMARK_ALIGN_V', 'bottom'); // top / bottom / center Define('WATERMARK_MARGIN', '10'); // margin // ---------------------------------------------------------------------------------------- $dr=preg_replace('/modify\.php.+/', '', $_SERVER['PHP_SELF']); $filename=str_replace($dr, './', $_SERVER['PATH_INFO']); if (!in_array(substr($filename, 0, 1), range(0, 9))){ readfile($filename); exit;} $lst=GetImageSize($filename); $image_width=$lst[0]; $image_height=$lst[1]; $image_format=$lst[2]; if ($image_format==1) { Header("Content-Type:image/gif"); readfile($filename); exit; } elseif ($image_format==2) { $old_image=imagecreatefromjpeg($filename); } elseif ($image_format==3) { $old_image=imagecreatefrompng($filename); } else { readfile($filename); exit; } if (Defined('WATERMARK_TEXT') && WATERMARK_TEXT!='') { // text $color = eregi_replace("#","", TEXT_COLOR); $red = hexdec(substr($color,0,2)); $green = hexdec(substr($color,2,2)); $blue = hexdec(substr($color,4,2)); $text_color = imagecolorallocate ($old_image, $red, $green, $blue); $text_height=imagefontheight(WATERMARK_TEXT_FONT); $text_width=strlen(WATERMARK_TEXT)*imagefontwidth(WATERMARK_TEXT_FONT); $wt_y=WATERMARK_MARGIN; if (WATERMARK_ALIGN_V=='top') { $wt_y=WATERMARK_MARGIN; } elseif (WATERMARK_ALIGN_V=='bottom') { $wt_y=$image_height-$text_height-WATERMARK_MARGIN; } elseif (WATERMARK_ALIGN_V=='center') { $wt_y=(int)($image_height/2-$text_height/2); } $wt_x=WATERMARK_MARGIN; if (WATERMARK_ALIGN_H=='left') { $wt_x=WATERMARK_MARGIN; } elseif (WATERMARK_ALIGN_H=='right') { $wt_x=$image_width-$text_width-WATERMARK_MARGIN; } elseif (WATERMARK_ALIGN_H=='center') { $wt_x=(int)($image_width/2-$text_width/2); } if (TEXT_SHADOW=='1') { imagestring($old_image, WATERMARK_TEXT_FONT, $wt_x+1, $wt_y+1, WATERMARK_TEXT, 0); } imagestring($old_image, WATERMARK_TEXT_FONT, $wt_x, $wt_y, WATERMARK_TEXT, $text_color); } if (Defined('WATERMARK_IMAGE') && WATERMARK_IMAGE!='' && file_exists(WATERMARK_IMAGE)) { // image $lst2=GetImageSize(WATERMARK_IMAGE); $image2_width=$lst2[0]; $image2_height=$lst2[1]; $image2_format=$lst2[2]; if ($image2_format==2) { $wt_image=imagecreatefromjpeg(WATERMARK_IMAGE); } elseif ($image2_format==3) { $wt_image=imagecreatefrompng(WATERMARK_IMAGE); } if ($wt_image) { $wt_y=WATERMARK_MARGIN; if (WATERMARK_ALIGN_V=='top') { $wt_y=WATERMARK_MARGIN; } elseif (WATERMARK_ALIGN_V=='bottom') { $wt_y=$image_height-$image2_height-WATERMARK_MARGIN; } elseif (WATERMARK_ALIGN_V=='center') { $wt_y=(int)($image_height/2-$image2_height/2); } $wt_x=WATERMARK_MARGIN; if (WATERMARK_ALIGN_H=='left') { $wt_x=WATERMARK_MARGIN; } elseif (WATERMARK_ALIGN_H=='right') { $wt_x=$image_width-$image2_width-WATERMARK_MARGIN; } elseif (WATERMARK_ALIGN_H=='center') { $wt_x=(int)($image_width/2-$image2_width/2); } imagecopymerge($old_image, $wt_image, $wt_x, $wt_y, 0, 0, $image2_width, $image2_height, WATERMARK_PERCENT); } } if ($image_format==2) { imageJpeg($old_image); } if ($image_format==3) { imagePng($old_image); } ?> PHP:
replace if (!in_array(substr($filename, 0, 1), range(0, 9))){ readfile($filename); exit;} with (if you want it to stop) if (!preg_match(/([\d]+)[\S]+$/iU",$filename,$match)) { exit;}