如何使用php缩放图像
有没有可能在php中缩放图像? 我在谷歌上搜索过,但什么也没找到如何使用php缩放图像,php,image,image-conversion,Php,Image,Image Conversion,有没有可能在php中缩放图像? 我在谷歌上搜索过,但什么也没找到 如果有人有什么建议,请给我。感谢您此处的ImageCopy重采样解决方案: $zoom=120; //to zoom 120% $width = imagesx($myimage); $height = imagesy($myimage); $new_width = $width * $zoom / 100; $new_height = $height * $zoom / 100; imagecopyresampled($im
如果有人有什么建议,请给我。感谢您此处的ImageCopy重采样解决方案:
$zoom=120; //to zoom 120%
$width = imagesx($myimage);
$height = imagesy($myimage);
$new_width = $width * $zoom / 100;
$new_height = $height * $zoom / 100;
imagecopyresampled($image_p, $myimage, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
ImageCopy在此重新采样解决方案:
$zoom=120; //to zoom 120%
$width = imagesx($myimage);
$height = imagesy($myimage);
$new_width = $width * $zoom / 100;
$new_height = $height * $zoom / 100;
imagecopyresampled($image_p, $myimage, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
如果您遵循php示例(并将其变大而不是变小-(php.net示例中演示了变小),并且如果您传递的是js变量,那么您将得到类似以下php的结果:
<?php
// The file
$imgin = $_POST["dogimg"];
//e.g if your img is called dogimg!
$percent = 1.4; //140%
// Content type
header('Content-Type: image/jpeg');
// Get new dimensions
list($width, $height) = getimagesize($imgin);
$new_width = $width * $percent;
$new_height = $height * $percent;
// Resample
$image_out = imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefromjpeg($imgin);
imagecopyresampled($image_out, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
// Output
imagejpeg($image_out, null, 100);
?>
但是,我应该指出,在处理图像等文件类型时,您应该小心,我建议您在开始时输入一些(如果您是通过网站上载图像,最好在上载图像时开始)
如果您正在使用已上载到服务器上的预上载图像,那么您应该可以继续使用。如果您遵循php示例(并使其变大而不是变小-(在php.net示例中演示了变小),并且如果您传递一个js变量,那么您将得到类似以下php的结果:
<?php
// The file
$imgin = $_POST["dogimg"];
//e.g if your img is called dogimg!
$percent = 1.4; //140%
// Content type
header('Content-Type: image/jpeg');
// Get new dimensions
list($width, $height) = getimagesize($imgin);
$new_width = $width * $percent;
$new_height = $height * $percent;
// Resample
$image_out = imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefromjpeg($imgin);
imagecopyresampled($image_out, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
// Output
imagejpeg($image_out, null, 100);
?>
但是,我应该指出,在处理图像等文件类型时,您应该小心,我建议您在开始时输入一些(如果您是通过网站上载图像,最好在上载图像时开始)
如果您正在处理已上载到服务器上的预上载图像,那么您应该可以继续使用。使用
使用
为什么?它是用来查看的吗?因为如果是这样的话,你可以在客户端使用javascript。如果你想用缩放的图像替换图像,你可以在PHP中使用我想查看的图像。谢谢你是否使用javscript传递图像(到PHP?)为什么?它是用来查看的吗?因为如果是这样的话,你可以在客户端使用javascript。如果你想用缩放的图像替换图像,你可以在PHP中使用我想查看的图像。谢谢你是否使用javscript传递图像(到PHP?)