【问题标题】:Uploaded image is not getting cropped上传的图片没有被裁剪
【发布时间】:2013-07-05 16:34:11
【问题描述】:

我想通过 PHP 网络服务使用 Android 应用程序上传图像。图片正在上传,但是 当我想裁剪上传的图像时,它失败了。 file_exixts 条件返回真。 我在我的网站上尝试过同样的事情,并成功上传和裁剪图像。

include_once('../crop1.php'); // for cropping an image
include_once('../config.php'); // for encrypting the name of the image

header('Content-Type: bitmap; charset=utf-8'); 
$filename = $_REQUEST['photo'];
$binary = base64_decode($filename);
$encrypted_name = name_encrypt($filename); // encrypting the name of the image

$final = "../upload/".$encrypted_name."jpg"; // Its attaching the extension to the image.

$file = fopen($final, 'wb'); // commented the original code

fwrite($file, $binary); // storing image to the folder


if (file_exists($final))  //checking if image exists
{
    crop_medium($encrypted_name.'jpg'); // if image exists then crop it by calling this function in the included file crop1.php
    $query = "INSERT INTO `error_log` (`param1`, `param2`, `date_time`) VALUES ('1', 'success_found', '2013-07-08')";
    $result = mysql_query($query);
} 

$return["status"] = "OK";
$return["message"] = "Uploaded successfully";

echo json_encode($return);
?>

在crop1.php中我有以下代码

<?php
function crop_medium($image_name)
{   
    include_once("resize-class.php"); // calling the php file to resize an uploaded image from the upload folder
    $resizeObj = new resize("upload/$encrypted_name"); 

    $resizeObj -> resizeImage(167, 121, 'crop'); // resizing and image in the given format

    $crop_image = "$encrypted_name";
    $resizeObj -> saveImage("cropped/$crop_image", 100); // saving resized image in other folder
}
?>

我编辑了我的问题。我在参数中传递了完整路径,现在我只通过参数传递图像名称。请帮助我哪里出错了。提前致谢。

【问题讨论】:

  • 什么是 $encrypted_name..?
  • 我在将图像的名称存储到我的服务器之前对其进行加密。在 config.php 文件中调用了加密图像的函数

标签: php image crop image-resizing


【解决方案1】:

你传递给函数的参数表变量

<?php
function crop_medium($image_name_with_full_path)
{ 

不是您在函数中使用的。

$resizeObj = new resize("upload/$encrypted_name"); 

【讨论】:

  • 请仅将其视为图像名称。我也尝试通过完整路径。但是现在我正在crop1.php的上传文件夹中搜索图像名称,因此我只是通过参数传递图像名称。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-01-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多