我有多個來自陣列的影像(可能是3個,也可能是10個),我想把它們放在彼此的旁邊,如果它們不再適合,就把它們放在一個新的行中。
我寫了一個foreach陳述句,并且我讓它起作用了,如果它們不適合當前的行,就把它們放到一個新的行中,并且它們也會彼此相鄰。
但是我的問題是圖片之間的間距,因為現在每張圖片的間距都不同。有些圖片之間的空間非常大,而有些則是重疊的。
這是我寫的函式:
function createAwardsTable(pdflib $p, int $textStartLeft, array $arrInput) {
$awardImages = $arrInput[' awards']。
$boxHeight = 50;
$x = $textStartLeft;
$y = 275;
foreach($awardImages as $awardImage) {
$image = $p->load_image("auto", $awardImage, "" ) 。
if ($image == 0) {
echo("無法加載$image: " . $p->get_errmsg())。)
exit(1)。
}
$imagewidth = $p->info_image($image, "imagewidth", ")。
if ($x > (565 - 20) ) {
$y = 215;
$x = $textStartLeft;
}
$buf = "boxsize={"/span> . $imagewidth . " " . $boxHeight . "} fitmethod=auto matchbox={name=awardimage}"。
//$buf = "scale=1 matchbox={name=awardimage}";.
$p->fit_image($image,$x,$y,$buf) 。
$awardWidth = $p->info_matchbox(" awardimage", 1, "x2") 。
$x = ($x - 20) $awardWidth;
}
uj5u.com熱心網友回復:
我認為你的邏輯到目前為止還不錯。
$awardWidth = $p-> info_matchbox("awardimage", 1, "x2") 。
$x = ($x - 20) $awardWidth。
我認為$x的新計算方法就是不大正確。如果我對你的描述理解正確的話,那么你只是想在之前放置的圖片旁邊的20個像素處輸出下一張獲獎圖片。如果是這樣的話,那么使用火柴盒來獲得所放置圖片的位置,然后在其上添加20像素就可以了。
$awardX2 = $p-> info_matchbox("awardimage", 1, "x2") 。
$x = $awardX2 20;
也許問題也來自于$awardWidth的錯誤名稱。Info_matchbox()回傳給你的是X位置,而不是寬度。如果你想要寬度,那么你也應該得到X1的位置,然后計算出差異。$width = $x2-$x1)
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/317212.html
標籤:

