[英]imagecopy - cropping image instead of resizing
我想調整大小 - $artfile
,並將商店從$start_x, $start_y
開始存入$dest
。
$dest
包含一個框架。 $artfile
需要適合框架,所以我需要調整它的大小。
我的代碼是:
imagecopy($dest, $art_file, $start_x, $start_y, 0, 0, $new_width, $new_height); // works fine but to test resize
$dest = my destination resource
$artfile = resource that I want to patch with $destination
$new_width, $new_height = I want $art_file to be resized to this value, without trimming off or cropping.
我的問題是:
對於具有超過$new_height
或$new_width
維度的任何圖像,修剪掉的圖像越多。 我想將整個集調整為$new_height
或$new_width
。
有幫助嗎?
玩這個,希望它可以幫助你一些;
<?php
Function createthumbnail($src=null,$newHeight=null) {
$srcimg = imagecreatefromjpeg($src);
$srcsize = getimagesize($src);
$dest_y = $newHeight;
$dest_x = ($newHeight / $srcsize[1]) * $srcsize[0];
$thumbimg = imagecreatetruecolor($dest_x, $dest_y);
imagecopyresampled($thumbimg,$srcimg,0,0,0,0,$dest_x,$dest_y, $srcsize[0], $srcsize[1]);
$thumbimg = imagejpeg($thumbimg,$src);
return $thumbimg;
}
?>
你可以這樣稱呼它
<?php
resizedImage = createthumbnail(urlOfFileToResize,newHeight);//newHeight would be like 1 or 50 or 1000......
?>
現在,您調整大小的圖像將存儲在resizedImage中
別客氣。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.