我有一个PHP脚本,可以重新调整JPEG图像的大小.但是,由于某种原因,图像被扭曲,即使我将其编程为按比例计算x或y(取决于照片方向).质量是100,所以我不明白为什么它会使它们扭曲.我究竟做错了什么?
编辑
原始图像为3264px x 2448px
原始图片:http: //imgur.com/DOsKf&hMAOh#0
重新调整大小:http: //imgur.com/DOsKf&hMAOh#1
谢谢
代码:
<?php
$im = ImageCreateFromJpeg('IMG_0168.jpg');
//Find the original height and width.
$ox = imagesx($im);
$oy = imagesy($im);
//Now we will determine the new height and width. For this example maximum height will
be 500px and the width will be 960px. To prevent inproper proportions we need to know
if the image is portrate or landscape then set one dimension and caluate the other.
$height = 500; …
Run Code Online (Sandbox Code Playgroud) 可能重复:
如何使strpos不区分大小写
我正在测试一个字符串是否包含"喜欢的人"的文字.嗯,代码很棒!除了区分大小写.我该怎么做才能防止这种情况发生?
如果字符串是"喜欢运行的人",则返回false如果字符串是"喜欢运行的人",则返回true
我希望它不区分大小写.
码:
<?php
$string = "People who like to run";
if (strrpos($string, 'People who like') === false) {
echo "False";
}
else {
echo "True";
}
Run Code Online (Sandbox Code Playgroud) 我有一个脚本可以将 PNG 文件转换为 JPEG 文件。除了,我不确定它是如何工作的。$outputPngFile 和 $outputJpgFile 有什么用?我可以用 tmp 文件来做到这一点,比如用户上传它时吗?那么,如何访问新文件以将其移动到正确的图像目录?
function pngTojpg($image, $outputPngFile, $outputJpgFile, $quality) {
$image = imagecreatefrompng($image);
//Save the png image
imagepng($image, $outputPngFile);
//Save the jpeg image
imagejpeg($image, $outputJpgFile, $quality);
// Free up memory
imagedestroy($image);
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用cookie来维护我网站上的登录持久性.但是,由于某些我不知道的原因,cookie尚未创建.仅创建会话.我正在使用Sessions来跟踪已登录的用户,并使用Cookie在他们回来时重新创建会话.我究竟做错了什么?
创建会话和cookie:
<?php
$connect= // connect variables
$query= "SELECT * FROM users where email= '$email' AND password=
'$password'";
$result= mysqli_query($connect, $query)
or die('error with query');
if (mysqli_num_rows($result) == 1) {
$row= mysqli_fetch_array($result);
session_start();
$_SESSION['id']= $row['user_id'];
$_SESSION['name']= $row['fname'] . " " . $row['lname'];
setcookie('id', $row['user_id']);
$profile_url= 'http://'. $_SERVER['HTTP_HOST'] .
dirname($_SERVER['PHP_SELF']) . '/profile.php';
header('Location:profile.php');
}
else {
$message= "Incorrect email/password combination.";
}
?>
Run Code Online (Sandbox Code Playgroud)
检查cookie以恢复会话:
<?php
session_start()
/* if a session does not exist, see if a cookie does to set the session …
Run Code Online (Sandbox Code Playgroud) 我有一个删除子句,删除我的数据库中"已查看"列日期时间值超过24小时的行.我有那个代码工作得很好,除了查看列的默认值是0000-00-00 00:00:00.在这种情况下,具有默认值的每一行数据也会被删除.如何更改查询以防止这种情况发生?
我的代码:
$delete_expired_notifications_query= "DELETE FROM notifications WHERE user_id= '".$u_id."'
AND viewed < NOW() - INTERVAL 24 HOUR";
Run Code Online (Sandbox Code Playgroud)
谢谢