热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Howtogetvariablewidth&heightwhencroppingwithJcropandsavewithPHPGD

Ihaveanapplicationthathastocropimageswithvariablewidth&height.butidontknowhow

I have an application that has to crop images with variable width & height. but i don't know how to do this with the php gd (Createimagefromjpeg) function

我有一个应用程序,必须裁剪宽度和高度可变的图像。但我不知道如何使用php gd(Createimagefromjpeg)函数执行此操作

in my code i have:

在我的代码我有:

$targ_w = 400;
$targ_h = 400;

This means that the cropped image will always get this width and height. that's not what i want. i want, in some way crop the images and crop it like i selected it at the crop area like in this picture:

这意味着裁剪后的图像将始终获得此宽度和高度。那不是我想要的。我希望,以某种方式裁剪图像并裁剪它,就像我在裁剪区域选择它一样,如下图所示:

cropped image

now when i crop that image, like in the picture i get this:

现在,当我裁剪图像时,就像在图片中我得到的那样:

square image created

It is a square image because i have to give a width and height. but at every image i crop the sizes are different.

这是一个方形图像,因为我必须给出宽度和高度。但在我裁剪的每一张图片上,尺寸都不同。

Is there a way (variables, id etc..) to do this?

有没有办法(变量,id等..)这样做?

Thanks :D

EDIT: my code to create the cropped image:

编辑:我创建裁剪图像的代码:




    







My code to upload the image:

我上传图片的代码:





    
    
    
    
    
    



Het "Vergeet-mij-nietje"

Upload Systeem

Upload hier een afbeelding en druk op upload om hem vervolgens te kunnen bijsnijden.



Bekijk hier de gecropte en geuploadde foto's

My code to crop the image with JCrop:

我用JCrop裁剪图像的代码:


    
    
      
    
    


Selecteer een album:

"; $handle = opendir($base); while (($file = readdir($handle))!==FALSE) { if (is_dir($base."/".$file) && $file != "." && $file !=".." && $file !="$uploads") { echo "$file
"; } } closedir($handle); } else { if (!is_dir($base."/".$get_album) || strstr($get_album,".")!=NULL || strstr($get_album,"/")!=NULL || strstr($get_album,"\\")!=NULL) { echo "Dit album bestaat niet."; } else { $x = 0; echo "$get_album

"; $handle = opendir($base."/".$get_album); while (($file = readdir($handle)) !== FALSE) { if ($file != "." && $file != "..") { echo "

"; $x++; } if ($x==$column) { echo "
"; $x = 0; } } } closedir($handle); echo "

Terug Naar Albums"; } ?>

1 个解决方案

#1


9  

Change the line from

改变行

$dst_r = ImageCreateTrueColor( $targ_w, $targ_h );

to

$dst_r = imagecreatetruecolor($_POST['w'], $_POST['h']);

=> this will create a new image with selected area, you can delete $targ_w and $targ_h variables.

=>这将创建一个具有选定区域的新图像,您可以删除$ targ_w和$ targ_h变量。

And change the line from

并改变行

imagecopyresampled($dst_r,$img_r,0,0,$_POST['x'],$_POST['y'],
$targ_w,$targ_h,$_POST['w'],$_POST['h']);

to

imagecopy(
    $dst_r, $img_r,
    0, 0, $_POST['x'], $_POST['y'],
    $_POST['w'], $_POST['h']
);

推荐阅读
  • 本文详细介绍了如何使用PHP检测AJAX请求,通过分析预定义服务器变量来判断请求是否来自XMLHttpRequest。此方法简单实用,适用于各种Web开发场景。 ... [详细]
  • 本文详细介绍了如何使用 Yii2 的 GridView 组件在列表页面实现数据的直接编辑功能。通过具体的代码示例和步骤,帮助开发者快速掌握这一实用技巧。 ... [详细]
  • 本文介绍了如何使用PHP代码实现微信平台的媒体素材上传功能,详细解释了API接口的使用方法和注意事项,确保文件路径正确以避免常见的错误。 ... [详细]
  • 在编译BSP包过程中,遇到了一个与 'gets' 函数相关的编译错误。该问题通常发生在较新的编译环境中,由于 'gets' 函数已被弃用并视为安全漏洞。本文将详细介绍如何通过修改源代码和配置文件来解决这一问题。 ... [详细]
  • 在寻找轻量级Ruby Web框架的过程中,您可能会遇到Sinatra和Ramaze。两者都以简洁、轻便著称,但它们之间存在一些关键区别。本文将探讨这些差异,并提供详细的分析,帮助您做出最佳选择。 ... [详细]
  • Explore a common issue encountered when implementing an OAuth 1.0a API, specifically the inability to encode null objects and how to resolve it. ... [详细]
  • 本文详细介绍了如何解决Uploadify插件在Internet Explorer(IE)9和10版本中遇到的点击失效及JQuery运行时错误问题。通过修改相关JavaScript代码,确保上传功能在不同浏览器环境中的一致性和稳定性。 ... [详细]
  • 深入理解Tornado模板系统
    本文详细介绍了Tornado框架中模板系统的使用方法。Tornado自带的轻量级、高效且灵活的模板语言位于tornado.template模块,支持嵌入Python代码片段,帮助开发者快速构建动态网页。 ... [详细]
  • 本文详细介绍了如何使用Python编写爬虫程序,从豆瓣电影Top250页面抓取电影信息。文章涵盖了从基础的网页请求到处理反爬虫机制,再到多页数据抓取的全过程,并提供了完整的代码示例。 ... [详细]
  • 本章将深入探讨移动 UI 设计的核心原则,帮助开发者构建简洁、高效且用户友好的界面。通过学习设计规则和用户体验优化技巧,您将能够创建出既美观又实用的移动应用。 ... [详细]
  • 本文介绍了在Windows Server 2003环境下,使用XAMPP Lite 1.7.1和DotProject 2.1.3时遇到的日历和甘特图中文乱码问题的解决方案。通过修改相关文件和配置,可以有效解决这些问题。 ... [详细]
  • 作为一名 Ember.js 新手,了解如何在路由和模型中正确加载 JSON 数据是至关重要的。本文将探讨两者之间的差异,并提供实用的建议。 ... [详细]
  • 采用IKE方式建立IPsec安全隧道
    一、【组网和实验环境】按如上的接口ip先作配置,再作ipsec的相关配置,配置文本见文章最后本文实验采用的交换机是H3C模拟器,下载地址如 ... [详细]
  • 本文详细介绍了虚拟专用网(Virtual Private Network, VPN)的概念及其通过公共网络(如互联网)构建临时且安全连接的技术特点。文章探讨了不同类型的隧道协议,包括第二层和第三层隧道协议,并提供了针对IPSec、GRE以及MPLS VPN的具体配置指导。 ... [详细]
  • 在 Flutter 开发过程中,开发者经常会遇到 Widget 构造函数中的可选参数 Key。对于初学者来说,理解 Key 的作用和使用场景可能是一个挑战。本文将详细探讨 Key 的概念及其应用场景,并通过实例帮助你更好地掌握这一重要工具。 ... [详细]
author-avatar
7777-丿M
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有