高度设置php,php – 图像处理宽度和高度设置

在我的项目中我只是做图像水印或图像结合它的工作正常和代码.

test

if(isset($_POST['submit']))

{

// Give the Complete Path of the folder where you want to save the image

$folder="uploads/";

move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], "$folder".$_FILES["fileToUpload"]["name"]);

$file='uploads/'.$_FILES["fileToUpload"]["name"];

$uploadimage=$folder.$_FILES["fileToUpload"]["name"];

$newname= time();

$ext = pathinfo($_FILES["fileToUpload"]["name"], PATHINFO_EXTENSION);

// Set the thumbnail name

$thumbnail = $folder.$newname.".".$ext;

$imgname=$newname.".".$ext;

// Load the mian image

if ($ext=="png" || $ext=="PNG") {

$source = imagecreatefrompng($uploadimage);

}

else if ($ext=="gif" || $ext=="GIF") {

$source = imagecreatefromgif($uploadimage);

}

else if ($ext=="bmp" || $ext=="BMP") {

$source = imagecreatefrombmp($uploadimage);

}

else{

$source = imagecreatefromjpeg($uploadimage);

}

// load the image you want to you want to be watermarked

$watermark = imagecreatefrompng('uploads/logo1.png');

// get the width and height of the watermark image

$water_width = imagesx($source)/2;

$water_height = imagesy($watermark);

// get the width and height of the main image image

$main_width = imagesx($source);

$main_height = imagesy($source);

$im_middle_w = $main_width/2;

$im_middle_h = $main_height/2;

// Set the dimension of the area you want to place your watermark we use 0

// from x-axis and 0 from y-axis

$dime_x = $im_middle_w - $water_width/2;

$dime_y = $im_middle_h - $water_height/2;

// copy both the images

imagecopy($source, $watermark, $dime_x, $dime_y, 0, 0, $water_width, $water_height);

// Final processing Creating The Image

imagejpeg($source, $thumbnail, 100);

unlink($file);

}

?>

<?php%20echo%20%24imgname;?>

但设置$water_width的问题,我想设置为我的源图像的一半.但是当我有一个宽度较小或宽度较宽的源图像与$water_width相比时,就像这样设置它.当源图像宽度更大时查看图像.

NlY5p.jpg

当宽度较小时.

JHj5v.jpg

所以我的问题是如何将$water_width设置为源图像宽度的一半?

通过亚历克斯你的回答它就像这样.

7Vlrp.jpg

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值