【问题标题】:How I can resize while uploading an image上传图片时如何调整大小
【发布时间】:2014-06-30 06:32:23
【问题描述】:

我需要在上传时调整图片大小。我需要添加什么来做到这一点?

html 文件:

> <form action="news.php?action=save" method="post"
> enctype="multipart/form-data" id="post" name="post" onsubmit="return
> chkFormular();"><ul>
>       <li>Newspic frontpage<br /><br />
>             <input name="banner" type="file" /> (width must be equal to: 307px)<br /><br />
>       </li>
>       </ul></form>

news.php:

$banner = $_FILES['banner'];
$id=$newsID;

    $filepath = "images/news_pics/";
if ($banner['name'] != "") {
    move_uploaded_file($banner['tmp_name'], $filepath.$banner['name']);
    @chmod($filepath.$banner['name'], 0755);
    $file_ext=strtolower(substr($banner['name'], strrpos($banner['name'], ".")));
    $file=$id.$file_ext;
    if(file_exists($filepath.$file)) @unlink($filepath.$file);
    rename($filepath.$banner['name'], $filepath.$file);
    safe_query("UPDATE ".PREFIX."news SET banner='$file' WHERE newsID = '".$newsID."'");

}

我想将图片的宽度调整为 307 像素,高度可以是自动的。并随之调整文件大小。

当然,我已经在

【问题讨论】:

  • 究竟是什么问题?
  • 这些是我的文件。我上传的东西效果很好,但我想做一些东西来调整图像的大小,同时上传宽度为 307px 和自动高度。这可能吗?
  • 这与 MySQL 或 CSS 没有任何关系。您可能希望调查 php 的 Gmagick 扩展。 php.net/manual/en/gmagick.examples.php

标签: php image image-processing


【解决方案1】:

http://www.sanwebe.com/2012/05/ajax-image-upload-and-resize-with-jquery-and-php

查看函数:resizeImage() 和cropImage()

相应地设置html中img的宽高。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-25
    • 2014-08-26
    • 2011-05-28
    • 1970-01-01
    相关资源
    最近更新 更多