相关疑难解决方法(0)

如何在PHP中使用switch case'或'?

有没有办法在php开关中使用'OR'运算符或等效运算符?例如,像这样:

switch ($value) {

    case 1 || 2:
        echo 'the value is either 1 or 2';
        break;
}
Run Code Online (Sandbox Code Playgroud)

php case switch-statement

220
推荐指数
7
解决办法
27万
查看次数

PHP - 从URL创建缩略图

我需要一种方法(使用内置的PHP库)从URL下拉图像并将其保存到本地磁盘,调整大小/缩放WIDTH到150px.我一直在尝试这个:

从上传的图像创建缩略图

function makeThumbnails($updir, $img, $id)
{
    $thumbnail_width = 134;
    $thumbnail_height = 189;
    $thumb_beforeword = "thumb";
    $arr_image_details = getimagesize("$updir" . $id . '_' . "$img"); // pass id to thumb name
    $original_width = $arr_image_details[0];
    $original_height = $arr_image_details[1];
    if ($original_width > $original_height) {
        $new_width = $thumbnail_width;
        $new_height = intval($original_height * $new_width / $original_width);
    } else {
        $new_height = $thumbnail_height;
        $new_width = intval($original_width * $new_height / $original_height);
    }
    $dest_x = intval(($thumbnail_width - $new_width) / 2);
    $dest_y = intval(($thumbnail_height - $new_height) / 2); …
Run Code Online (Sandbox Code Playgroud)

php image-processing

9
推荐指数
1
解决办法
2万
查看次数

质量更好的缩略图

我有一个成功创建缩略图的脚本,但它们的质量很低.是否有一些我可以在脚本中更改以使缩略图质量更好的东西?

function createThumbnail($filename) {

    $final_width_of_image = 200;
    $path_to_image_directory = 'images/fullsized/';
    $path_to_thumbs_directory = 'images/thumbs/';

    if(preg_match('/[.](jpg)$/', $filename)) {
        $im = imagecreatefromjpeg($path_to_image_directory . $filename);
    } else if (preg_match('/[.](gif)$/', $filename)) {
        $im = imagecreatefromgif($path_to_image_directory . $filename);
    } else if (preg_match('/[.](png)$/', $filename)) {
        $im = imagecreatefrompng($path_to_image_directory . $filename);
    }

    $ox = imagesx($im);
    $oy = imagesy($im);

    $nx = $final_width_of_image;
    $ny = floor($oy * ($final_width_of_image / $ox));

    $nm = imagecreatetruecolor($nx, $ny);

    imagecopyresized($nm, $im, 0,0,0,0,$nx,$ny,$ox,$oy);

    if(!file_exists($path_to_thumbs_directory)) {
      if(!mkdir($path_to_thumbs_directory)) {
           die("There was a problem. Please try again!");
      }
       } …
Run Code Online (Sandbox Code Playgroud)

php image thumbnails

2
推荐指数
1
解决办法
3254
查看次数