#!/usr/bin/php \n"; exit; } ini_set('memory_limit', '128M'); $image = $argv[1]; $output_file = $argv[2]; $output_quality = 80; print "Watermarking $image ... "; $im = ImageCreateFromJpeg($image); if(!$im) die("Not a valid JPEG Image"); $width = ImageSx($im); $height= ImageSy($im); $exif = exif_read_data($image, 0, true); if($exif and isset($exif['IFD0']['Orientation'])) { if($exif['IFD0']['Orientation'] != 1) { $temp = $width; $width = $height; $height = $temp; $im = imagerotate($im, 90, 0); } } if($width > $height) { $strip_height = intval($height / 13); } else { // Vertical pictures - potrait format. $strip_height = intval($width / 13); } $new_height = $strip_height * 2 + $height; $newimage = imagecreatetruecolor($width, $new_height); $strip_color = imagecolorallocate($newimage, 0, 0, 0); imagefilledrectangle($newimage,0,0,$width,$strip_height,$strip_color); imageCopyResampled($newimage,$im,0,$strip_height,0,0,$width,$height,$width,$height); $watermark_image = imagecreatefrompng("Sample_WaterMark.png"); $watermark_height = ImageSy($watermark_image); $watermark_width = ImageSx($watermark_image); $watermark_new_hight = intval($strip_height * 90/100); // The watermark should be 90% of the black strip. $watermark_new_width = intval($watermark_width * ($watermark_new_hight / $watermark_height)); $watermark_place_x = $width - $watermark_new_width - ($width / 30); $watermark_place_y = $height + $strip_height + intval(($strip_height - $watermark_new_hight)/2); // imagecopyresampled ( resource $dst_image , resource $src_image , int $dst_x , int $dst_y , int $src_x , int $src_y , int $dst_w , int $dst_h , int $src_w , int $src_h ) imageCopyResampled($newimage,$watermark_image, $watermark_place_x,$watermark_place_y, 0,0, $watermark_new_width,$watermark_new_hight, $watermark_width,$watermark_height); imagejpeg($newimage, $output_file, $output_quality); print "Done\n";