小编Ale*_*ans的帖子

在PHP中调整图像大小

我想写一些PHP代码,自动调整通过表单上传到147x147px的任何图像,但我不知道如何去做(我是一个相对的PHP新手).

到目前为止,我已成功上传图片,识别文件类型并清理名称,但我想将调整大小功能添加到代码中.例如,我有一个2.3MB的测试图像,尺寸为1331x1331,我希望代码可以缩小尺寸,我猜测它也会大大压缩图像的文件大小.

到目前为止,我有以下内容:

if ($_FILES) {
                //Put file properties into variables
                $file_name = $_FILES['profile-image']['name'];
                $file_size = $_FILES['profile-image']['size'];
                $file_tmp_name = $_FILES['profile-image']['tmp_name'];

                //Determine filetype
                switch ($_FILES['profile-image']['type']) {
                    case 'image/jpeg': $ext = "jpg"; break;
                    case 'image/png': $ext = "png"; break;
                    default: $ext = ''; break;
                }

                if ($ext) {
                    //Check filesize
                    if ($file_size < 500000) {
                        //Process file - clean up filename and move to safe location
                        $n = "$file_name";
                        $n = ereg_replace("[^A-Za-z0-9.]", "", $n);
                        $n = strtolower($n);
                        $n = "avatars/$n";
                        move_uploaded_file($file_tmp_name, $n); …
Run Code Online (Sandbox Code Playgroud)

php image-processing image-upload image-resizing

75
推荐指数
7
解决办法
28万
查看次数

AngularJS - ng-bind不更新

我有一个控制器,它具有从API获取一些警报的功能,并更新我的站点前端的计数,该计数绑定到警报.

不幸的是,ng-bind我正在使用的属性似乎并没有实时更新计数,即使一个简单console.log()的告诉我实际警报计数正在控制器中更新.

前端

<div class="modeSelector modeSelector_oneUp" data-ng-controller="MyLivestockController as vm">
    <a class="modeSelector-mode" data-ui-sref="my-livestock">
        <div class="modeSelector-type">Alerts</div>

        <img class="modeSelector-icon" src="/inc/img/_icons/envelope-black.svg" onerror="this.src=envelope-black.png" />

        <span data-ng-bind="vm.alertCount"></span>
    </a>
</div>
Run Code Online (Sandbox Code Playgroud)

调节器

(function() {

  'use strict';

  function MyLivestockController(userService) {

    var vm = this;

    vm.myLivestockNotification = {
      isLoading: true,
      hasError: false
    };

    vm.alertsNotification = {
      isLoading: true,
      hasError: false,
      hasData: false
    };

    vm.deleteAlert = function(id) {

      vm.currentAlert = void 0;
      vm.alertsNotification.isLoading = true;

      userService.deleteAlert(vm.user.id, id).then(function() {

        // Remove the alert from our Array
        vm.alerts = …
Run Code Online (Sandbox Code Playgroud)

javascript angularjs

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

使用dompdf将页面转换为PDF

我正在尝试使用dompdf将PHP页面转换为PDF,但我不确定最好的方法.我已经在页面上写了我希望它如何以标准HTML/PHP呈现,并希望它像这样显示,就像PDF一样:

期望的输出

我的PHP代码如下.我相信我需要将我的代码放入$html变量中以解析为dompdf,但我有点像一个PHP新手,所以会很感激一些帮助,知道实现这一目标的最佳方法是什么.显然,页面的样式都是从外部CSS文件引入的,所以我不确定这是不是一个问题?

<?php
    include("checklog.php"); 
    require_once("watchlist-controller.php");
    require_once("dompdf/dompdf_config.inc.php");
    $html = 
?>
<!DOCTYPE html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="shortcut icon" href="img/fav.ico">
        <link rel="apple-touch-icon" href="img/apple-touch-icon.png">
        <title>Screening - Your ticket to your movies - <?php echo $watchlist_name; ?></title>
        <meta name="description" content="Screening is a brand new take on the traditional movie database, fusing social networking and multimedia to provide a clear, concise experience allowing you to share your favourite movies, and discover new classics.">
        <meta name="keywords" content="Movies, Films, Screening, Discover, Watch, Share, …
Run Code Online (Sandbox Code Playgroud)

php pdf dompdf mpdf

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