如何使用Intervention Image调整图像大小以保持纵横比,但使图像的最短边适合所需的调整大小比率。
E.g。调整大小以适应100x100的800x400图像将调整为200x100
我试过了:
$image->resize($width, $height, function ($constraint) {
$constraint->aspectRatio();
});
但它调整了最长的一面以适应(例如100x50)。
答案 0 :(得分:6)
将宽度设为public class MyActivity extends Activity {
public String activityString; // Here static or not no difference. This is null
public static WifiManager wifi;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.locationscreen);
wifiScanResults();
String[] dataArray = activityString.split("\\.");
// Here I got Null Referance exception. When I debug, activityString is null
}
public void wifiScanResults()
{
wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context c, Intent intent) {
activityString = "Go";
}
}, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
wifi.startScan();
}
:
null
以编程方式说,只需查找哪一侧更大并将其设置为$height = 100;
$image = Image::make('800x400.jpg')->resize(null, $height, function ($constraint) {
$constraint->aspectRatio();
});
$image->save('200X100.jpg', 60);
,即:
null