为简单起见,我可以说我有一个需要显示图像缩略图的网页.图像位置存储在数据库中(图像存储在Amazon S3上).在将大型图像传送到客户端之前,是否可以让我的Web服务器缩小?这样我就不必存储每个图像的缩略图,客户端可以下载较小的文件.
我想将图片尺寸从600px*500px缩小到60px*50px,然后裁剪成50px*50px.我有两组代码,一组是缩小图像大小,另一组是裁剪图像.问题是它们是分开工作的,如何将这两组代码结合起来使它们一起工作?以下是我的代码:
<?php
//codes of group A - Reduce the size of image from 600px * 500px to 60px * 50px
$save2 = "images/users/" . $image_name_2; //This is the new file you saving
list($width2, $height2) = getimagesize($file) ;
$modwidth2 = 50;
$diff2 = $width2 / $modwidth2;
$modheight2 = $height2 / $diff2;
$tn2 = imagecreatetruecolor($modwidth2, $modheight2) ;
$image2 = imagecreatefromjpeg($file) ;
imagecopyresampled($tn2, $image2, 0, 0, 0, 0, $modwidth2, $modheight2, $width2, $height2) ;
imagejpeg($tn2, $save2, 100) ;
//codes of group B - Crop …Run Code Online (Sandbox Code Playgroud) 我正在寻找复制,调整大小和移动图像.这与wordpress在上传时如何创建不同大小的图像类似.我希望这可以执行,而不会在运行页面时上传任何内容.
例:
$imagePath = 'http://example.com/images/myimageonserver.jpg';
$newImagePath = 'http://example.com/images/new/myimageonserver.jpg';
$newImageWidth = 300;
$newImageHeight = 200;
Run Code Online (Sandbox Code Playgroud)
有谁知道会这样做的脚本?或者一些有用的功能可以完成这项工作.
我一直试图弄清楚如何在 PHP 中调整上传图像的大小,使其不小于给定的大小 (650x650)。但是,如果用户上传的图像在任一边缘都小于我的 650 最小值,则无需采取任何措施。
场景 1 - 上传 2000 像素宽 x 371 像素的图像 - 这不会调整大小,因为 371 像素已经小于我的最小值。
场景 2 - 上传了 2000 像素 x 1823 像素的图像 - 在这里我应该将图像调整为尽可能接近最小值,但不允许宽度或高度低于 650 像素。
到目前为止,这是我一直在思考的路线(我正在使用优秀的 simpleImage 脚本来帮助调整大小和获取尺寸):
$curWidth = $image->getWidth();
$curHeight = $image->getHeight();
$ratio = $curWidth/$curHeight;
if ($curWidth>$minImageWidth && $curHeight>$minImageHeight)
{
//both dimensions are above the minimum, so we can try scaling
if ($curWidth==$curHeight)
{
//perfect square :D just resize to what we want
$image->resize($minImageWidth,$minImageHeight);
}
else if ($curWidth>$curHeight)
{
//height is …Run Code Online (Sandbox Code Playgroud) 我想要一个功能,可以在不丢失纵横比的情况下调整图像的特定高度和重量。所以首先我想裁剪它然后调整它的大小。
这是我到目前为止得到的:
function image_resize($src, $dst, $width, $height, $crop=1){
if(!list($w, $h) = getimagesize($src)) return "Unsupported picture type!";
$type = strtolower(substr(strrchr($src,"."),1));
if($type == 'jpeg') $type = 'jpg';
switch($type){
case 'bmp': $img = imagecreatefromwbmp($src); break;
case 'gif': $img = imagecreatefromgif($src); break;
case 'jpg': $img = imagecreatefromjpeg($src); break;
case 'png': $img = imagecreatefrompng($src); break;
default : return "Unsupported picture type!";
}
// resize
$originalW = $w;
$originalH = $h;
if($crop){
if($w < $width or $h < $height) return "Picture is too small!";
$ratio = …Run Code Online (Sandbox Code Playgroud) 我的问题是,我根据毫米到像素调整图片大小,然后将其打印出来,这永远不会准确。我的问题是有一种方法可以让 java 以毫米或任何其他公制单位而不是像素进行绘制,因为像素永远不会精确到毫米。
我正在开发一个项目,需要在网站的不同部分使用各种尺寸的用户图片.要提供的图像是各种尺寸的主要图像的缩略图,例如35×35像素,50×50像素和100×100像素.我想让用户只上传一张图片.
我使用PHP和Apache作为webserver.该网站最初的访问量估计约为40万,并且可能会显着增加.我的问题是:
我应该将图片调整为我需要的各种尺寸,同时在上传时保留原件吗?或者我应该只在需要和显示时调整图片大小(使用类似于phpThumb的东西)?
请我想知道这是更好的性能和速度智慧和资源管理明智的,考虑到交通的水平,并有可能在给定的时间是高达100网站上的并发用户.
我正在尝试上传图像和调整图像大小.我想要图像原始图像和拇指图像.
但问题是图像调整大小代码不起作用.
图像上传代码工作正常,它将图像存储在文件夹中,但图像大小调整代码不起作用.
我怎样才能做到这一点 ?
这是我的代码
public function add_images(){
$this->form_validation->set_rules('description','Description','required');
$this->form_validation->set_rules('status','Status','required');
if($this->form_validation->run() == TRUE) {
// print_r($this->input->post());
$config['upload_path'] = 'public/img/inner_images/';
$config['allowed_types'] = 'gif|jpg|jpeg|png'; // upload only valid images
// update library setting of upload
$this->load->library('upload', $config);
//upload image
$this->upload->do_upload('image');
$fInfo = $this->upload->data(); // get all info of uploaded file
//for image resize
$img_array = array();
$img_array['image_library'] = 'gd2';
$img_array['maintain_ratio'] = TRUE;
$img_array['create_thumb'] = TRUE;
//you need this setting to tell the image lib which image to process
$img_array['source_image'] = $fInfo['full_path']; …Run Code Online (Sandbox Code Playgroud) 我写了一个方法来为我调整 BufferedImages 的大小,但这样做之后 .png 图像最终失去了它们的透明度,而是得到了黑色背景。
public BufferedImage getSizedImg(BufferedImage otherImage,int width,int height){
BufferedImage outputImg = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics g = outputImg.createGraphics();
g.drawImage(otherImage, 0, 0, width, height, null);
g.dispose();
return outputImg;
}
Run Code Online (Sandbox Code Playgroud)
如何修复该方法以使图像保持透明度?
我想从url获取图像,然后在不保存的情况下调整大小
var request = require('request');
request
.get('s3url')
.on('response', function (response) {
console.log(response) // 200
console.log(response.headers['content-type']) // 'image/png'
})
.pipe(res)
Run Code Online (Sandbox Code Playgroud)
我现在可以用requestlib 返回相同的图片,但是我如何操作它然后作为响应返回?
image-resizing ×10
php ×6
image ×3
crop ×2
java ×2
thumbnails ×2
amazon-s3 ×1
asp.net ×1
c# ×1
codeigniter ×1
express ×1
function ×1
gd ×1
imagick ×1
lwjgl ×1
node.js ×1
phpthumb ×1
printing ×1
size ×1
transparency ×1