我需要在ImageMagick或GD库之间进行选择,以执行以下图像处理任务:
如你所见,我不需要任何花哨的东西.我确信这两个工具都可以实现它们,所以如果一个人有比另一个更多的额外功能,我真的不在乎.
我主要关心的是性能和质量.这两种工具中哪一种消耗的资源更少,速度更快,产生更高质量的图像?
PS我需要将它与各自的PHP API一起使用.
在我的一个应用程序中,我正在使用下面的代码片段将上传的图像复制到目录中.它工作正常,但复制大图像(> 2MB)需要比理想时间更多的时间,我真的不需要这么大的图像,所以,我正在寻找一种方法来调整图像的大小.如何使用PHP实现这一目标?
<?php
$uploadDirectory = 'images/0001/';
$randomNumber = rand(0, 99999);
$filename = basename($_FILES['userfile']['name']);
$filePath = $uploadDirectory.md5($randomNumber.$filename);
// Check if the file was sent through HTTP POST.
if (is_uploaded_file($_FILES['userfile']['tmp_name']) == true) {
// Validate the file size, accept files under 5 MB (~5e+6 bytes).
if ($_FILES['userfile']['size'] <= 5000000) {
// Move the file to the path specified.
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $filePath) == true) {
// ...
}
}
}
?>
Run Code Online (Sandbox Code Playgroud) 我正面临一个奇怪的问题。如果我使用 PHP 上传图像并且我上传的图像损坏或随机上传了一半。所以图像在服务器上显示如下:
此外,我只是使用 ajax post 方法并将表单数据中的图像发送到 PHP 后端。
var formData = new FormData();
formData.append('loop_logo', $('.loop_logo_public')[0].files[0]);
var image = $('.loop_logo_public')[0].files[0];
var fsize = image.size;
formData.append('file_size',fsize);
$.ajax({
xhr: function() {
var xhr = new window.XMLHttpRequest();
return xhr;
},
method: 'post',
url: mainurl + 'api.php?type=create_post',
contentType: false,
processData: false,
data: formData
}).done(function(data) {
//other actions
});
Run Code Online (Sandbox Code Playgroud)
根据这个处理android半上传/损坏上传的图像到服务器我已经验证了上传之前和上传之后的文件大小。文件大小根本没有变化。
这是我用于文件上传的后端代码。
$mainurl="https://example.com/";
class SimpleImage {
var $image;
var $image_type;
function load($filename) {
$image_info = getimagesize($filename);
$this->image_type = $image_info[2];
if( $this->image_type == IMAGETYPE_JPEG ) …Run Code Online (Sandbox Code Playgroud) 我不知道如何在PHP中调整图像大小,我的代码是:
for ($index = 1; $index <= 2; $index++) {
if (!empty($_FILES["pic$index"]["name"])) {
$ext = substr($_FILES["pic$index"]["name"], strrpos($_FILES["pic$index"]["name"], '.') + 1);
$dir = "../gallery/$mkdir";
HERE I NEED THE RESIZE OF THE TMP FILE OF IMAGE
move_uploaded_file($_FILES["pic$index"]["tmp_name"] , "$dir/img-$index.$ext");
}
}
Run Code Online (Sandbox Code Playgroud)
$ mkdir =画廊文件夹的名称(有很多画廊).
$ dir =将放置图片的位置.
$ ext =图像的类型(png,gif或jpg).
foreach循环运行两次因为你可以上传两张照片.
这个脚本运行良好,我只需要调整大小,我不知道如何做到这一点..
目前,我正在使用CKEditor 4angular-ckeditor添加。
在我的模板中,将其显示为:
<div ng-repeat="editor in editors">
<div ckeditor="options" ng-model="editor.content"></div>
</div>
Run Code Online (Sandbox Code Playgroud)
我正在寻找一种将图像从桌面上传到CKEditor的方法。据我了解,angular-ckeditor和CKEditor库是分开的,所以我可以轻松地添加控件和插件。
问题是我似乎找不到合适的插件/小工具(不使用jQuery),这将帮助我从桌面上载图像。我使它仅适用于图像链接。
官方网站上没有很多相关文档。他们说要使用将上传和浏览图像的PHP文件,但是并没有真正解释如何使用,特别是使用angular-ckeditor。所以我现在有几个问题:
到目前为止,我什至没有尝试更改CKEditor选项卡(它应该通过添加“上传”选项卡和其他一些UI 来更改图像属性对话框)。所以很明显,我在所有这些地方都缺少可靠的教程。
(我也可以尝试切换到 ng-ckeditor,如果这样的解决方案会更简单)
我正在使用此 php 代码将图像从电脑上传到服务器
$ImageToLoad=mysql_real_escape_string($_POST['image_attached']);
if($ImageToLoad){
$token=$token;//variable
$ImageToLoad = str_replace('data:image/png;base64,', '', $ImageToLoad);
$ImageToLoad = str_replace('data:image/jpeg;base64,', '', $ImageToLoad);
$ImageToLoad = str_replace(' ', '+', $ImageToLoad);
$fileData = base64_decode($ImageToLoad);
$destino_path="/images/$token/image.png";
file_put_contents($destino_path, $fileData);
}
Run Code Online (Sandbox Code Playgroud)
工作正常。
问题
我需要知道如何在将图像存储在服务器之前调整其大小/裁剪它们。否则它会保持相同的大小(巨大图像时出现问题)
我制作了一个负责上传图像的文件,然后将这些图像移动到服务器中的文件夹中.我想我不能直接在$ _FILES数组中调整图像大小,所以我想我必须在服务器中调整图像大小,所以我的问题是,如何调整服务器中的图像?
这是我的代码的一部分:
//This is after getting target which is the file saved on the server
move_uploaded_file($_FILES[$str]['tmp_name'], $target);
scale_image($target);
Run Code Online (Sandbox Code Playgroud)
现在函数scale_image()
function scale_image($image)
{
if(!empty($image)) //the image to be uploaded is a JPG I already checked this
{
$source_image = imagecreatefromjpeg($image);
$source_imagex = imagesx($source_image);
$source_imagey = imagesy($source_image);
$dest_imagex = 300;
$dest_imagey = 200;
$image = imagecreatetruecolor($dest_imagex, $dest_imagey);
imagecopyresampled($image, $source_image, 0, 0, 0, 0,
$dest_imagex, $dest_imagey, $source_imagex, $source_imagey);
}
}
Run Code Online (Sandbox Code Playgroud)
但这似乎不起作用,它移动文件但没有调整大小.
php ×7
image ×3
gd ×2
angularjs ×1
broken-image ×1
ckeditor ×1
file-upload ×1
imagemagick ×1
javascript ×1
resize ×1