热门标签 | 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']
);

推荐阅读
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社区 版权所有