我想在根目录写入一个名为xxx.php的文件,文件内容是
$filename= $_GET['filename'];
$width = $_GET['width'];
$height = $_GET['height'];
$path="img/"; //finish in "/"4399_17315873250.jpg
// Content type
header('Content-type: image/jpeg');
// Get new dimensions
list($width_orig, $height_orig) = getimagesize($path.$filename);
$dst_scale = $height/$width; //目标图像长宽比
$src_scale = $height_orig/$width_orig; // 原图长宽比
if ($src_scale>=$dst_scale){ // 过高
$w = intval($width_orig);
$h = intval($dst_scale*$w);
$x = 0;
$y = ($height_orig - $h)/2;
} else { // 过宽
$h = intval($height_orig);
$w = intval($h/$dst_scale);
$x = ($width_orig - $w)/2;
$y = 0;
}// 剪裁
$source=imagecreatefromjpeg($path.$filename);
$croped=imagecreatetruecolor($w, $h);
imagecopy($croped, $source, 0, 0, $x, $y, $width_orig, $height_orig);
// 缩放
$scale = $width / $w;
$image_p = imagecreatetruecolor($width, $height);
$final_w = intval($w * $scale);
$final_h = intval($h * $scale);
imagecopyresampled($image_p, $croped, 0, 0, 0, 0, $final_w,$final_h, $w, $h);// Output
imagejpeg($image_p, null, 100);
// Imagedestroy
imagedestroy ($image_p);
请问该怎么写啊,前台调用<img src="xxx.php?filename=photo.jpg&width=100&height=100">
$filename= $_GET['filename'];
$width = $_GET['width'];
$height = $_GET['height'];
$path="img/"; //finish in "/"4399_17315873250.jpg
// Content type
header('Content-type: image/jpeg');
// Get new dimensions
list($width_orig, $height_orig) = getimagesize($path.$filename);
$dst_scale = $height/$width; //目标图像长宽比
$src_scale = $height_orig/$width_orig; // 原图长宽比
if ($src_scale>=$dst_scale){ // 过高
$w = intval($width_orig);
$h = intval($dst_scale*$w);
$x = 0;
$y = ($height_orig - $h)/2;
} else { // 过宽
$h = intval($height_orig);
$w = intval($h/$dst_scale);
$x = ($width_orig - $w)/2;
$y = 0;
}// 剪裁
$source=imagecreatefromjpeg($path.$filename);
$croped=imagecreatetruecolor($w, $h);
imagecopy($croped, $source, 0, 0, $x, $y, $width_orig, $height_orig);
// 缩放
$scale = $width / $w;
$image_p = imagecreatetruecolor($width, $height);
$final_w = intval($w * $scale);
$final_h = intval($h * $scale);
imagecopyresampled($image_p, $croped, 0, 0, 0, 0, $final_w,$final_h, $w, $h);// Output
imagejpeg($image_p, null, 100);
// Imagedestroy
imagedestroy ($image_p);
请问该怎么写啊,前台调用<img src="xxx.php?filename=photo.jpg&width=100&height=100">
吧生成的图片路径直接传到html里面就可以了
$myfile = fopen("xxx.php", "w") or die("Unable to open file!");
$txt = "xxxxxxxxx";
fwrite($myfile, $txt);
fclose($myfile);
这样可以直接生成一个文件
$filename= $_GET['filename'];
$width = $_GET['width'];
$height = $_GET['height'];
$path="img/"; //finish in "/"4399_17315873250.jpg
// Content type
header('Content-type: image/jpeg');
// Get new dimensions
list($width_orig, $height_orig) = getimagesize($path.$filename);
$dst_scale = $height/$width; //目标图像长宽比
$src_scale = $height_orig/$width_orig; // 原图长宽比
if ($src_scale>=$dst_scale){ // 过高
$w = intval($width_orig);
$h = intval($dst_scale*$w);
$x = 0;
$y = ($height_orig - $h)/2;
} else { // 过宽
$h = intval($height_orig);
$w = intval($h/$dst_scale);
$x = ($width_orig - $w)/2;
$y = 0;
}// 剪裁
$source=imagecreatefromjpeg($path.$filename);
$croped=imagecreatetruecolor($w, $h);
imagecopy($croped, $source, 0, 0, $x, $y, $width_orig, $height_orig);
// 缩放
$scale = $width / $w;
$image_p = imagecreatetruecolor($width, $height);
$final_w = intval($w * $scale);
$final_h = intval($h * $scale);
imagecopyresampled($image_p, $croped, 0, 0, 0, 0, $final_w,$final_h, $w, $h);// Output
imagejpeg($image_p, null, 100);
// Imagedestroy
imagedestroy ($image_p);
TXT
file_put_contents('xxx.php', $s);
$s =<<< 'TXT'
$width = $_GET['width'];
$height = $_GET['height'];
$path="img/"; //finish in "/"4399_17315873250.jpg
// Content type
header('Content-type: image/jpeg');
// Get new dimensions
list($width_orig, $height_orig) = getimagesize($path.$filename);
$dst_scale = $height/$width; //目标图像长宽比
$src_scale = $height_orig/$width_orig; // 原图长宽比
if ($src_scale>=$dst_scale){ // 过高
$w = intval($width_orig);
$h = intval($dst_scale*$w);
$x = 0;
$y = ($height_orig - $h)/2;
} else { // 过宽
$h = intval($height_orig);
$w = intval($h/$dst_scale);
$x = ($width_orig - $w)/2;
$y = 0;
}// 剪裁
$source=imagecreatefromjpeg($path.$filename);
$croped=imagecreatetruecolor($w, $h);
imagecopy($croped, $source, 0, 0, $x, $y, $width_orig, $height_orig);
// 缩放
$scale = $width / $w;
$image_p = imagecreatetruecolor($width, $height);
$final_w = intval($w * $scale);
$final_h = intval($h * $scale);
imagecopyresampled($image_p, $croped, 0, 0, 0, 0, $final_w,$final_h, $w, $h);// Output
imagejpeg($image_p, null, 100);
// Imagedestroy
imagedestroy ($image_p);
TXT
file_put_contents('xxx.php', $s);
?>
从第三行开始报错