php縮略裁切文檔介紹內容的簡單介紹

本文目錄一覽:

php怎麼讀文件內容拆分內容

打開文件

while(!文件結尾){

$str=讀取一行

$arr[]=explode(“/”,$str);

}

關閉文件

$arr是一個二維數組

php求助圖片縮放裁切問題

這段代碼可以通過自已選擇來決定圖片的大小!

效果圖如下所示:希望對你有幫助!

其中

minSize: [48,48],

setSelect: [0,0,190,190],

是調整選取範圍的大小,若你 調整為120和160就改為了

setSelect: [0,0,120,160],

就可以了!

?php

error_reporting(7);

date_default_timezone_set(“Asia/Shanghai”);

header(“Content-type:text/html; Charset=utf-8”);

require_once(“./image.class.php”);

$images = new Images(“file”);

if ($_GET[‘act’] == ‘cut’){ 

 $image = “0000.jpg”;

 $res = $images-thumb($image,false,1);

 if($res == false){

  echo “裁剪失敗”;

 }elseif(is_array($res)){

  echo ‘img src=”‘.$res[‘big’].'” style=”margin:10px;”‘;

  echo ‘img src=”‘.$res[‘small’].'” style=”margin:10px;”‘;

 }elseif(is_string($res)){

  echo ‘img src=”‘.$res.'”‘;

 }

}elseif(isset($_GET[‘act’])  $_GET[‘act’] == “upload”){

 

 $path = $images-move_uploaded();

 $images-thumb($path,false,0);       //文件比規定的尺寸大則生成縮略圖,小則保持原樣

 if($path == false){

  $images-get_errMsg();

 }else{

  echo “上傳成功!a href='”.$path.”‘ target=’_blank’查看/a”;

 }

}else{

?

!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN” “;quot;;

html

 head

  meta name=”Author” content=”SeekEver”

  meta name=”Keywords” content=””

  meta name=”Description” content=””

  meta content=”text/html; charset=UTF-8″ http-equiv=”Content-Type”

  script src=”./js/jquery.min.js” type=”text/javascript”/script

  script src=”./js/jquery.Jcrop.js” type=”text/javascript”/script

  link rel=”stylesheet” href=”./css/jquery.Jcrop.css” type=”text/css” /

script type=”text/javascript”

  jQuery(function($){

    // Create variables (in this scope) to hold the API and image size

      var jcrop_api, boundx, boundy;

     

      $(‘#target’).Jcrop({

  minSize: [48,48],

  setSelect: [0,0,190,190],

        onChange: updatePreview,

        onSelect: updatePreview,

  onSelect: updateCoords,

        aspectRatio: 1

      },

 function(){

        // Use the API to get the real image size

        var bounds = this.getBounds();

        boundx = bounds[0];

        boundy = bounds[1];

        // Store the API in the jcrop_api variable

        jcrop_api = this;

    });

 function updateCoords(c)

 {

  $(‘#x’).val(c.x);

  $(‘#y’).val(c.y);

  $(‘#w’).val(c.w);

  $(‘#h’).val(c.h);

 };

 function checkCoords()

 {

  if (parseInt($(‘#w’).val())) return true;

  alert(‘Please select a crop region then press submit.’);

  return false;

 };

      function updatePreview(c){

        if (parseInt(c.w)  0)

        {

          var rx = 48 / c.w;  //小頭像預覽Div的大小

          var ry = 48 / c.h;

        $(‘#preview’).css({

            width: Math.round(rx * boundx) + ‘px’,

            height: Math.round(ry * boundy) + ‘px’,

            marginLeft: ‘-‘ + Math.round(rx * c.x) + ‘px’,

            marginTop: ‘-‘ + Math.round(ry * c.y) + ‘px’

          });

        }

     {

          var rx = 199 / c.w;  //大頭像預覽Div的大小

          var ry = 199 / c.h;

          $(‘#preview2’).css({

            width: Math.round(rx * boundx) + ‘px’,

            height: Math.round(ry * boundy) + ‘px’,

            marginLeft: ‘-‘ + Math.round(rx * c.x) + ‘px’,

            marginTop: ‘-‘ + Math.round(ry * c.y) + ‘px’

          });

        }

      };

    });

/script

 /head

 body

 form method=”post” action=”?act=upload” enctype=”multipart/form-data”

  input type=”file” name=”file”

  input type=”submit” value=”上傳”

 /form

 div style=”float:left;”img id=”target” src=”0000.jpg”  /div

 div style=”width:48px;height:48px;margin:10px;overflow:hidden; float:left;”img  style=”float:left;” id=”preview” src=”0000.jpg” /div

 div style=”width:190px;height:195px;margin:10px;overflow:hidden; float:left;”img  style=”float:left;” id=”preview2″ src=”0000.jpg” /div

 form action=”index.php?act=cut” method=”post” onsubmit=”return checkCoords();”

  input type=”hidden” id=”x” name=”x” /

  input type=”hidden” id=”y” name=”y” /

  input type=”hidden” id=”w” name=”w” /

  input type=”hidden” id=”h” name=”h” /

  input type=”submit” value=”裁剪” /

 /form

 /body

/html

?php

?

求如何用php讀取指定文件夾中的所有圖片,生成縮略圖,在網頁上分頁顯示,單擊縮略圖就在新頁面顯示大圖。

生成縮略圖採用讀取文件夾的方式

$handle = opendir($dir)

while(false !== ($file = readdir($handle)))

{

if($file 是圖片)

{

生成縮略圖代碼

}

}

原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/270012.html

(0)
打賞 微信掃一掃 微信掃一掃 支付寶掃一掃 支付寶掃一掃
小藍的頭像小藍
上一篇 2024-12-16 13:35
下一篇 2024-12-16 13:35

相關推薦

  • Python簡單數學計算

    本文將從多個方面介紹Python的簡單數學計算,包括基礎運算符、函數、庫以及實際應用場景。 一、基礎運算符 Python提供了基礎的算術運算符,包括加(+)、減(-)、乘(*)、除…

    編程 2025-04-29
  • Python滿天星代碼:讓編程變得更加簡單

    本文將從多個方面詳細闡述Python滿天星代碼,為大家介紹它的優點以及如何在編程中使用。無論是剛剛接觸編程還是資深程序員,都能從中獲得一定的收穫。 一、簡介 Python滿天星代碼…

    編程 2025-04-29
  • 使用Spire.PDF進行PDF文檔處理

    Spire.PDF是一款C#的PDF庫,它可以幫助開發者快速、簡便地處理PDF文檔。本篇文章將會介紹Spire.PDF庫的一些基本用法和常見功能。 一、PDF文檔創建 創建PDF文…

    編程 2025-04-29
  • Python海龜代碼簡單畫圖

    本文將介紹如何使用Python的海龜庫進行簡單畫圖,並提供相關示例代碼。 一、基礎用法 使用Python的海龜庫,我們可以控制一個小海龜在窗口中移動,並利用它的“畫筆”在窗口中繪製…

    編程 2025-04-29
  • Python七年級內容用法介紹

    本文將從多個方面對Python七年級內容進行詳細闡述。 一、安裝Python 要使用Python進行編程,首先需要在計算機上安裝Python。Python可以在官網上免費下載。下載…

    編程 2025-04-29
  • Python櫻花樹代碼簡單

    本文將對Python櫻花樹代碼進行詳細的闡述和講解,幫助讀者更好地理解該代碼的實現方法。 一、簡介 櫻花樹是一種圖形效果,它的實現方法比較簡單。Python中可以通過turtle這…

    編程 2025-04-28
  • Python爬蟲文檔報告

    本文將從多個方面介紹Python爬蟲文檔的相關內容,包括:爬蟲基礎知識、爬蟲框架及常用庫、爬蟲實戰等。 一、爬蟲基礎知識 1、爬蟲的定義: 爬蟲是一種自動化程序,通過模擬人的行為在…

    編程 2025-04-28
  • Python獲取Flutter上內容的方法及操作

    本文將從以下幾個方面介紹Python如何獲取Flutter上的內容: 一、獲取Flutter應用數據 使用Flutter提供的Platform Channel API可以很容易地獲…

    編程 2025-04-28
  • Python大神作品:讓編程變得更加簡單

    Python作為一種高級的解釋性編程語言,一直被廣泛地運用於各個領域,從Web開發、遊戲開發到人工智能,Python都扮演着重要的角色。Python的代碼簡潔明了,易於閱讀和維護,…

    編程 2025-04-28
  • Python少兒編程的學習內容

    Python被譽為是最適合新手入門的編程語言之一,它簡潔易懂,同時涵蓋了廣泛的編程知識。Python的少兒編程課程也因其易學性和實用性越來越受到家長和孩子們的歡迎。接下來我們將從多…

    編程 2025-04-28

發表回復

登錄後才能評論