php 删除图像周围的像素边框
php remove pixels border around an image
我使用以下代码显示远程图像并缓存它的本地版本。
现在我需要找到一种方法来移除图像周围的 10 个像素,因为在图像 displayed/cached.
之前需要移除一个边框
如何使用 php 删除图像顶部、底部、右侧和左侧的 10 个像素?
header('Content-type: image/png');
$path = ".......";
$CACHE_FILE_PATH = "images_tshirts/mini_t/".$a.".png";
if(file_exists($CACHE_FILE_PATH)) {
echo @file_get_contents($CACHE_FILE_PATH);
}
else {
$image = imagecreatefromstring(file_get_contents($path));
// Send the image
imagepng($image, $CACHE_FILE_PATH);
echo @file_get_contents($CACHE_FILE_PATH);
exit();
}
?>
imagecrop — Crop an image using the given coordinates and size, x, y,
width and height
http://php.net/manual/en/function.imagecrop.php
编辑:根据要求来自链接页面的示例。修改以考虑 10 像素边框:
<?php
// Create a blank image and add some text
$ini_filename = 'test.JPG';
$im = imagecreatefromjpeg($ini_filename );
$ini_x_size = getimagesize($ini_filename )[0];
$ini_y_size = getimagesize($ini_filename )[1];
//the minimum of xlength and ylength to crop.
$crop_measure = min($ini_x_size, $ini_y_size);
// Set the content type header - in this case image/jpeg
//header('Content-Type: image/jpeg');
$to_crop_array = array('x' =>0 , 'y' => 0, 'width' => $crop_measure, 'height'=> $crop_measure);
$thumb_im = imagecrop($im, $to_crop_array);
imagejpeg($thumb_im, 'thumb.jpeg', 100);
?>
我使用以下代码显示远程图像并缓存它的本地版本。
现在我需要找到一种方法来移除图像周围的 10 个像素,因为在图像 displayed/cached.
之前需要移除一个边框如何使用 php 删除图像顶部、底部、右侧和左侧的 10 个像素?
header('Content-type: image/png');
$path = ".......";
$CACHE_FILE_PATH = "images_tshirts/mini_t/".$a.".png";
if(file_exists($CACHE_FILE_PATH)) {
echo @file_get_contents($CACHE_FILE_PATH);
}
else {
$image = imagecreatefromstring(file_get_contents($path));
// Send the image
imagepng($image, $CACHE_FILE_PATH);
echo @file_get_contents($CACHE_FILE_PATH);
exit();
}
?>
imagecrop — Crop an image using the given coordinates and size, x, y, width and height
http://php.net/manual/en/function.imagecrop.php
编辑:根据要求来自链接页面的示例。修改以考虑 10 像素边框:
<?php
// Create a blank image and add some text
$ini_filename = 'test.JPG';
$im = imagecreatefromjpeg($ini_filename );
$ini_x_size = getimagesize($ini_filename )[0];
$ini_y_size = getimagesize($ini_filename )[1];
//the minimum of xlength and ylength to crop.
$crop_measure = min($ini_x_size, $ini_y_size);
// Set the content type header - in this case image/jpeg
//header('Content-Type: image/jpeg');
$to_crop_array = array('x' =>0 , 'y' => 0, 'width' => $crop_measure, 'height'=> $crop_measure);
$thumb_im = imagecrop($im, $to_crop_array);
imagejpeg($thumb_im, 'thumb.jpeg', 100);
?>