第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

用PHP裁剪圖像

用PHP裁剪圖像

PHP
動(dòng)漫人物 2019-11-07 10:43:26
下面的代碼可以很好地裁剪圖像,這是我想要的,但是對(duì)于較大的圖像,它也可以正常工作。有什么辦法可以縮小圖像嗎?想法是,在裁剪之前,我將能夠使每個(gè)圖像的大小大致相同,以便每次都能獲得良好的效果代碼是<?php$image = $_GET['src']; // the image to crop$dest_image = 'images/cropped_whatever.jpg'; // make sure the directory is writeable$img = imagecreatetruecolor('200','150');$org_img = imagecreatefromjpeg($image);$ims = getimagesize($image);imagecopy($img,$org_img, 0, 0, 20, 20, 200, 150);imagejpeg($img,$dest_image,90);imagedestroy($img);echo '<img src="'.$dest_image.'" ><p>';
查看完整描述

3 回答

?
寶慕林4294392

TA貢獻(xiàn)2021條經(jīng)驗(yàn) 獲得超8個(gè)贊

如果要生成縮略圖,則必須首先使用調(diào)整圖像大小imagecopyresampled();。您必須調(diào)整圖像的大小,以使圖像較小側(cè)的尺寸等于拇指的相應(yīng)側(cè)。


例如,如果源圖像為1280x800px,拇指為200x150px,則必須將圖像的尺寸調(diào)整為240x150px,然后將其裁剪為200x150px。這樣一來(lái),圖像的長(zhǎng)寬比就不會(huì)改變。


這是創(chuàng)建縮略圖的一般公式:


$image = imagecreatefromjpeg($_GET['src']);

$filename = 'images/cropped_whatever.jpg';


$thumb_width = 200;

$thumb_height = 150;


$width = imagesx($image);

$height = imagesy($image);


$original_aspect = $width / $height;

$thumb_aspect = $thumb_width / $thumb_height;


if ( $original_aspect >= $thumb_aspect )

{

   // If image is wider than thumbnail (in aspect ratio sense)

   $new_height = $thumb_height;

   $new_width = $width / ($height / $thumb_height);

}

else

{

   // If the thumbnail is wider than the image

   $new_width = $thumb_width;

   $new_height = $height / ($width / $thumb_width);

}


$thumb = imagecreatetruecolor( $thumb_width, $thumb_height );


// Resize and crop

imagecopyresampled($thumb,

                   $image,

                   0 - ($new_width - $thumb_width) / 2, // Center the image horizontally

                   0 - ($new_height - $thumb_height) / 2, // Center the image vertically

                   0, 0,

                   $new_width, $new_height,

                   $width, $height);

imagejpeg($thumb, $filename, 80);

還沒(méi)有測(cè)試過(guò),但是應(yīng)該可以。


編輯


現(xiàn)在經(jīng)過(guò)測(cè)試并可以工作。


查看完整回答
反對(duì) 回復(fù) 2019-11-07
  • 3 回答
  • 0 關(guān)注
  • 411 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)