我正在使用PHP旋转和裁剪图像,但我显示黑色边框,我知道你可以改变背景颜色,但我想旋转并裁剪图像以填充整个图像.基本上类似于background-size: cover;(左)CSS和background-size: contain;(右).
看下图,右边是我现在得到的,左边是我想要达到的.旋转的度数是动态的,要生成的图像和源图像都是方形(200x200).

编辑:这是我的快速和脏代码:
$rotate = imagecreatefromjpeg($image);
// part of code created by www.thewebhelp.com, modified
$square_size = 200;
$original_width = imagesx($rotate);
$original_height = imagesy($rotate);
if($original_width > $original_height){
$new_height = $square_size;
$new_width = $new_height*($original_width/$original_height);
}
if($original_height > $original_width){
$new_width = $square_size;
$new_height = $new_width*($original_height/$original_width);
}
if($original_height == $original_width){
$new_width = $square_size;
$new_height = $square_size;
}
$new_width = round($new_width);
$new_height = round($new_height);
$smaller_image = imagecreatetruecolor($new_width, $new_height);
$square_image = imagecreatetruecolor($square_size, $square_size);
imagecopyresampled($smaller_image, $rotate, 0, 0, 0, 0, …Run Code Online (Sandbox Code Playgroud) 这不是一个答案,会得到一个正确的答案,但我会问它反正:
是否可以对图像进行磁化或放大,使其不会模糊?
例如,这不应该发生,像素不应该相互模糊,而应该放大块像素.maginification: block;在CSS或HTML中是否有类似或类似的东西,或者JS填充?
我有一些for {}在整个项目中反复使用的 javascript 循环,它们都与此类似:
for (var i = 0; i < things.length; i++) {
console.log(things[i]);
// This may be different in different areas of the project
}
Run Code Online (Sandbox Code Playgroud)
我缩小了代码,但是循环占用了很多缩小后的代码。有没有办法将上面的代码缩短为这样:
loop {
console.log(things[i]);
// This may be different in different areas of the project
}
Run Code Online (Sandbox Code Playgroud)
可能不是上面的内容,但你明白了。任何帮助将非常感激 :)
blur ×1
crop ×1
css ×1
html ×1
image ×1
imagemagick ×1
javascript ×1
minify ×1
optimization ×1
php ×1