-
<?php
-
header ( "Content-type: text/html; charset=utf-8" );
-
date_default_timezone_set ('PRC' ); //Set China time zone
-
include 'PHPExcel.php';
-
$dir=dirname(__FILE__);
-
$filename = "/Users/jiangminghui/Documents/test/hantai/hantaipic.xlsx";
-
$objPHPExcel = PHPExcel_IOFactory::load($filename);//Load file
-
$sheet = $objPHPExcel->getSheet(0);
-
$highestRow = $sheet->getHighestRow(); // Get the total number of rows
-
$highestColumn = $sheet->getHighestColumn(); // Get the total number of columns
-
$src_path1 = '111.png';
-
$src_path2 = '222.png';
-
$src1 = imagecreatefromstring(file_get_contents($src_path1));
-
$src2 = imagecreatefromstring(file_get_contents($src_path2));
-
list($src_w1, $src_h1) = getimagesize($src_path1);
-
list($src_w2, $src_h2) = getimagesize($src_path2);
-
for($i=1;$i<=$highestRow;$i++) {
-
$A = $objPHPExcel->getActiveSheet()->getCell("A".$i)->getValue();
-
$B = $objPHPExcel->getActiveSheet()->getCell("B".$i)->getValue();
-
$C = $objPHPExcel->getActiveSheet()->getCell("C".$i)->getValue();
-
//Get pictures from the server++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++
-
$url = 'https://xx.xx.com'.$C;
-
$ext = strrchr($url, ".");
-
$filename = $A.'_'.$B.$ext;
-
ob_start();//Open the output
-
readfile($url);//output picture file
-
$img = ob_get_contents();//Get browser output
-
ob_end_clean();//Clear output and close
-
$size = strlen($img);//Get the picture size
-
$fp2 = @fopen($filename, "a");
-
fwrite($fp2, $img);//Write the picture file to the current directory and rename it
-
fclose($fp2);
-
//usleep(200000);
-
//return $filename;//Return the new file name
-
$dst_path = 'img/'.$filename;
-
//Create an example of the picture++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++
-
$dst = imagecreatefromstring(file_get_contents($dst_path));
-
//Get the width and height of the watermark image
-
list($src_w0, $src_h0) = getimagesize($dst_path);
-
//Copy the watermark picture to the target picture, the last parameter 50 is to set the transparency, here the semi-transparent effect is achieved
-
imagecopymerge($dst, $src1, 10, 10, 0, 0, $src_w1, $src_h1, 100);
-
//If the watermark picture itself has a transparent color, use the imagecopy method
-
imagecopy($dst, $src2, $src_w0-$src_w2-10, $src_h0-$src_h2-10, 0, 0, $src_w2, $src_h2);
-
//Output picture
-
list($dst_w, $dst_h, $dst_type) = getimagesize($dst_path);
-
switch ($dst_type) {
-
case 1://GIF
-
header('Content-Type: image/gif');
-
imagegif ($ dst, $ filename);
-
break;
-
case 2://JPG
-
header('Content-Type: image/jpeg');
-
imagejpeg($dst,$filename);
-
break;
-
case 3://PNG
-
header('Content-Type: image/png');
-
imagepng($dst,$filename);
-
break;
-
default:
-
break;
-
}
-
imagedestroy($dst);
-
echo "$i";
-
}
-
imagedestroy($src1);
-
imagedestroy($src2);
-
?>
PHP gets server image and add watermark
Guess you like
Origin blog.csdn.net/zl17822307869/article/details/114006885
Recommended
Ranking