我有一个上传脚本调整上传的图像的大小,但是,当我不想要它们时,某些图像被保存为旋转图像,以任何方式保留原始图像方向?
if (($resizeObj->width > 400) || ($resizeObj->height > 600)){
// *** 2) Resize image (options: exact, portrait, landscape, auto, crop)
$resizeObj -> resizeImage(400, 400, 'crop');
// *** 3) Save image
$resizeObj -> saveImage($path, 95);
}
Run Code Online (Sandbox Code Playgroud)
这是我的类文件:
<?php
# ========================================================================#
#
# Author: Jarrod Oberto
# Version: 1.0
# Date: 17-Jan-10
# Purpose: Resizes and saves image
# Requires : Requires PHP5, GD library.
# Usage Example:
# include("classes/resize_class.php");
# $resizeObj = new resize('images/cars/large/input.jpg');
# $resizeObj -> resizeImage(150, 100, 0);
# …Run Code Online (Sandbox Code Playgroud) 快速简介.我们目前必须根据我们网站上的产品图片制作小型,中型和大型图片.不是PHP的知识我认为我仍然会尝试自动化这个噩梦.
我们上传的图片和拇指的尺寸如下
800 width x 1400 width LARGE
300 width x 525 width THUMB
Run Code Online (Sandbox Code Playgroud)
我的PHP脚本的问题在于它只是根据比例调整大小.我希望它能像Photoshop一样缩小,你只需点击移动,图像就可以缩放.我想用imagecopyresized但运气不好.
<?php
// PHP UPLOAD SCRIPT
// VALIDATION OF FORM
if($_FILES['user_image']['type'] == "image/jpeg" && $_FILES['user_image']['size'] < 3000000)
{
// VARS
$target_folder = 'images/';
$upload_image = $target_folder.basename($_FILES['user_image']['name']);
// UPLOAD FUNCTION
if(move_uploaded_file($_FILES['user_image']['tmp_name'], $upload_image))
{
// VARS FOR FILE NAMES
$thumbnail = $target_folder."medium_x.jpg";
$actual = $target_folder."large_x.jpg";
// THUMBNAIL SIZE
list($width, $height) = getimagesize($upload_image);
$newwidth = "300";
$newheight = "525";
// VARS FOR CALL BACK
$thumb = imagecreatetruecolor($newwidth, …Run Code Online (Sandbox Code Playgroud) 我正在以编程方式将图片上传到我的 Wordpress 媒体库,并将它们设置为我的帖子的特色图片,效果很好。
我想生成这些特色图像的缩略图,就像 Wordpress 在通过“插入媒体”窗格添加图像时处理创建调整大小的缩略图的方式相同,在其中创建多个文件,每个文件都具有在文件名中指定的新尺寸。
不幸的是,我很难找到任何解释如何正确执行此操作的内容。
下面是相关代码。它成功地创建了帖子并将特色图片设置为媒体文件,但不会生成与之配套的缩略图。
任何帮助将不胜感激!
// If the post was created
if($post_id) {
// Add meta/custom field data
add_post_meta($post_id, 'gif_random_id', $randomId);
// Add uploaded file to the actual Wordpress image library
global $uploadURL;
$filename = $uploadURL . $randomId . '.' . $fileExtension;
$wp_filetype = wp_check_filetype(basename($filename), null);
$wp_upload_dir = wp_upload_dir();
$attachment = array(
'guid' => $wp_upload_dir['url'] . '/' . basename($filename),
'post_mime_type' => $wp_filetype['type'],
'post_title' => preg_replace('/\.[^.]+$/', '', basename($filename)),
'post_content' => '',
'post_status' => 'publish'
);
$attach_id = …Run Code Online (Sandbox Code Playgroud) 我正在尝试调整我使用FileUpload控件上传的jpg图像,并在将其保存到数据库(SQL Server 2008)之前将其转换为byte(varbinary(MAX)).我所做的和下面的代码显示我设法将其转换为字节并作为varbinary(MAX)保存到数据库中.我想知道如何在完成所有这些功能之前调整图像大小.帮帮我吧 谢谢!
阅读文件
string filePath = FileUpload1.PostedFile.FileName;
string filename = Path.GetFileName(filePath);
string ext = Path.GetExtension(filename);
Run Code Online (Sandbox Code Playgroud)
根据文件扩展名设置contenttype
string contenttype = String.Empty;
switch (ext)
{
case ".jpg":
contenttype = "image/jpg";
break;
}
Run Code Online (Sandbox Code Playgroud)
转换为字节并使用varbinary保存到数据库中
if (contenttype != String.Empty)
{
Stream fs = FileUpload1.PostedFile.InputStream;
BinaryReader br = new BinaryReader(fs);
Byte[] bytes = br.ReadBytes((Int32)fs.Length);
//insert the file into database
string strQuery = "insert into MemberReport(username, typeofcrime, location, crdatetime, citizenreport, image1, image2, image3, image4, image5)" +
" values ('" + username + "','" + …Run Code Online (Sandbox Code Playgroud) 我正在整理 HTML+JS 代码以在自动将表单提交到服务器之前调整图片大小。我最初编写了用于自动提交表单的代码,然后添加了用于调整图像大小的逻辑。自动表单提交有效,但图像大小调整无效。请提供指导。先感谢您。
<!DOCTYPE html>
<html>
<head>
<title>Flask App</title>
<meta name="viewport" content="width=device-width, initial-scale=1, user-
scalable=no">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"></script>
<script src="http://malsup.github.com/jquery.form.js"></script>
<script type="text/javascript">
$(function(){
//JS Code snippet 1 - Automatic form submission on file selection
$("#file_select").change(function(){
$("#upload_form").submit();
$("#upload_form_div").hide();
$("#loading").show();
//JS Code snippet 2 - Image Resizing
var filesToUpload = inputs.files;
var img = document.createElement("img");
var reader = new FileReader();
reader.onload = function(e) {img.src = e.target.result}
reader.readAsDataURL(file);
var ctx = canvas.getContext("2d");
ctx.drawImage(img, 0, 0);
var MAX_WIDTH = 800;
var MAX_HEIGHT = 600;
var …Run Code Online (Sandbox Code Playgroud) 有没有一种有效的方法可以在不使用任何插值的情况下在OpenCV中调整图像大小?而不是常规的“调整大小”,我希望图像将像素重新映射为更大的图像,但将其他所有内容都填充为0。
例如,将img1扩展到低于img2的2倍:
img1 = [ 1, 2, 3,
4, 5, 6,
7, 8, 9 ]
cv::resize(img1, img2, cv::Size(6, 6));
img2 = [ 1, 0, 2, 0, 3, 0,
0, 0, 0, 0, 0, 0,
4, 0, 5, 0, 6, 0,
0, 0, 0, 0, 0, 0,
7, 0, 8, 0, 9, 0,
0, 0, 0, 0, 0, 0 ]
Run Code Online (Sandbox Code Playgroud)
我知道明显的方法是只使用for循环,但是我想知道是否有使用OpenCV调用的更有效的方法?
AFAIK,它应该是可能的。我知道convertImageMagick 使这项任务变得微不足道,但我不能使用 ImageMagick,因此我倾向于 Gimp(在 Windows 上)。
我已经尝试过这个 Guile 脚本:
(define (resize-image filename new-filename scale)
(let* ((image (car (gimp-file-load RUN-NONINTERACTIVE filename filename)))
(drawable (car (gimp-image-get-active-layer image)))
(width (gimp-image-width image))
(height (gimp-image-height image)))
(gimp-image-scale-full image (* width scale) (* height scale) INTERPOLATION-CUBIC)
(gimp-file-save RUN-NONINTERACTIVE image drawable new-filename new-filename)
(gimp-image-delete image)))
Run Code Online (Sandbox Code Playgroud)
我运行的:
gimp-2.8 -i -b "(resize-image \"image.jpg\" \"image-small.jpg\" 0.5)" -b "(gimp-quit 0)"
Run Code Online (Sandbox Code Playgroud)
但我收到此错误:
(gimp-2.8:22244): LibGimpBase-WARNING **: gimp-2.8: gimp_wire_read(): error
(gimp-2.8:22244): LibGimpBase-WARNING **: gimp-2.8: gimp_wire_read(): error
batch command experienced an execution error: …Run Code Online (Sandbox Code Playgroud) 我在其他许多人中看到了这个有趣的线程:在不使用画布的情况下在JavaScript中调整Base-64图像的大小
但是,当我使用创建一个屏幕外画布
const canvas = document.createElement('canvas');
Run Code Online (Sandbox Code Playgroud)
结果图像是透明的,大小甚至不匹配参数.如果我在DOM的画布上画一切都很好
const canvas = document.getElementById('canvas');
Run Code Online (Sandbox Code Playgroud)
这是我的调整大小功能,保持输入图像比例:
resizeImage(file) {
const canvas = document.createElement('canvas');
// const canvas = document.getElementById('canvas');
const context = (<HTMLCanvasElement>canvas).getContext('2d');
// set maximum width and height of output image
const maxW = 400;
const maxH = 400;
const img = new Image;
img.onload = function () {
const iw = img.width;
const ih = img.height;
const scale = Math.min((maxW / iw), (maxH / ih));
const iwScaled = iw * scale;
const ihScaled …Run Code Online (Sandbox Code Playgroud) 所以我有一个图像加载器,在将文件上传到Amazon S3之前,它使用以下代码优化图像:
<cfset ImageScaleToFit(myImage,1260,"")>
<cfset imageWrite(myimage,"newImagelocation", 0.9)>
Run Code Online (Sandbox Code Playgroud)
奇怪的是,如果我上传的图像已经是1260宽,24k大小,那么使用上面的代码对其进行优化,图像大小为34k.
为什么优化图像会使图像更大?
我想读取一个视频文件,将其分成单独的帧,将每个帧的大小调整为最大宽度,然后检索最终图像的宽度和高度。
我试过这个:
为真:
vs = cv2.VideoCapture(args["video"])
# grab the frame from the threaded video stream and resize it
# to have a maximum width of 400 pixels
frame = vs.read()
frame = imutils.resize(frame, width=400)
# grab the frame dimensions and convert it to a blob
w, h = cv.GetSize(frame)
Run Code Online (Sandbox Code Playgroud)
但我得到:
Traceback (most recent call last):
File "real_time_object_detection.py", line 52, in <module>
frame = imutils.resize(frame, width=400)
File "/home/pi/.virtualenvs/cv/lib/python3.5/site-packages/imutils/convenience.py", line 69, in resize
(h, w) = image.shape[:2]
AttributeError: 'tuple' object has no …Run Code Online (Sandbox Code Playgroud) image-resizing ×10
image ×3
file-upload ×2
opencv ×2
php ×2
upload ×2
attachment ×1
c# ×1
c++ ×1
coldfusion ×1
cv2 ×1
gimp ×1
html ×1
iphone ×1
javascript ×1
jquery ×1
photoshop ×1
python ×1
rotation ×1
sql-server ×1
thumbnails ×1
typescript ×1
varbinarymax ×1
video ×1
windows ×1
wordpress ×1