php_imagick method to realize image cutting, rotation, sharpening, color reduction or adding special effects, _PHP tutorial
php_imagick is a method for cutting, rotating, sharpening, color subtracting or adding special effects to images, The example in this article describes the method of php_imagick to realize image cutting, rotation, sharpening, color reduction or adding special effects. Share it with everyone for your reference. The specific analysis is as follows: A PHP extension that allows PHP to call ImageMagick functions. Using this extension allows PHP to have the same functionality as ImageMagick. ImageMagick is a powerful, stable and free toolset and development package that can be used to read, write and process image files in more than 185 basic formats, including popular TIFF, JPEG, GIF, PNG, PDF and PhotoCD and other formats. Using ImageMagick, you can dynamically generate images according to the needs of web applications. You can also change the size, rotate, sharpen, reduce color or add special effects to an image (or a group of images), and save the results in the same format. or save in other formats. php_imagick is an extension package for PHP image processing. It can complete operations such as changing the size, rotating, sharpening, subtracting colors or adding special effects to images. 1. Install Imagick extension under windows: 1. Download ImageMagick and…
PHP file upload class example that can generate thumbnails, _PHP tutorial
php can generate thumbnail file upload class examples, The example in this article describes the file upload class and its usage that can generate thumbnails in PHP. Share it with everyone for your reference. The specific implementation method is as follows: The class file calling method is as follows: The code is as follows: <? php if ($_GET[‘action’] == ‘save’) { $up = new upload(); $up->set_dir(dirname(__FILE__).’/upload/’,'{y}/{m}’); $up->set_thumb(100,80); $up->set_watermark(dirname(__FILE__).’/jblog/images/watermark.png’,6,90); $fs = $up->execute(); var_dump($fs); } ?> uploadThe uploaded files are as follows: The code is as follows: class upload { var $dir; //The physical directory where attachments are stored var $time; //Customized file upload time var $allow_types; //Allow attachment types to upload var $field; //Upload control name var $maxsize; //Maximum allowed file size, unit is KB var $thumb_width; //Thumbnail width var $thumb_height; //Thumbnail height var $watermark_file; //Watermark image address var $watermark_pos; //watermark position var $watermark_trans;//Watermark transparency //Open source code phpfensi.com //Constructor //$types: File types allowed to be uploaded, $maxsize: Allowed size, $field: Upload control name, $time: Customized upload time function upload($types = ‘jpg|png’, $maxsize = 1024, $field = ‘attach’, $time = ”) { $this->allow_types = explode(‘|’,$types); $this->maxsize = $maxsize * 1024; $this->field = $field; $this->time = $time ? $time : time(); }…
Using the image processing library Integration/Image in Laravel, _PHP tutorial
Using the image processing library Integration/Image in Laravel, System requirements PHP >= 5.3 Fileinfo Extension GD Library (>=2.0) … or … Imagick PHP extension (>=6.5.7) Installation and deployment Integration/imageAdd the [require] section in composer.json and then execute composer update “intervention/image”: “2.0.15” Laravel Configuration After the installation and deployment of Integration/image is completed, open the configuration file config/app.php and add code in the corresponding location, and then the Image class will be automatically loaded and available for use. It’s powerful enough to handle almost all your image processing needs. //Service Provider ‘Intervention\Image\ImageServiceProvider’ //Alias configuration ‘Image’ => ‘Intervention\Image\Facades\Image’ Configuration settingsBy default, Integration/Image uses PHP’s GD library extension. If you want to switch to imagick, you can use php artisan to create a configuration file to add the corresponding configuration. $ php artisan config:publish intervention/imag Basic usage Here are several basic functions. For more detailed instructions, please check the relevant interface documents. 1. Display a picture Route::get(‘/’, function() { $img = Image::make(‘foo.jpg’)->resize(300, 200); return $img->response(‘jpg’); }); 2. Read an image file $img = Image::make(‘foo/bar/baz.jpg’); 3. Draw a picture $img = Image::canvas(800, 600, ‘#ccc’); 4. Edit a picture $img = Image::make(‘foo.jpg’)->resize(320, 240)->insert(‘watermark.png’); http://www.bkjia.com/PHPjc/928615.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/928615.htmlTechArticleUsing the image processing library Integration/Image in Laravel, the system requires PHP…
How to intercept a specified image size in PHP, _PHP tutorial
PHP method to intercept specified image size, The example in this article describes the method of intercepting the specified image size in PHP. Share it with everyone for your reference. The specific analysis is as follows: imagecopyresampled($newim, $im, 0, 0, 7, 174, 120, 42, $new_img_width, $new_img_height); // Original size 120 x 42 imagecopyresampled($newim, $im, 0, 0, 100, 30, 500, 500, $new_img_width, $new_img_height); //Cut out the image and place it at 500 x 500 imagecopyresampled($newim, $im, 0, 0, 100, 30, 10, 10, $new_img_width, $new_img_height); // The image is cut out and reduced to 10 x 10 It’s probably just the operation of this function. Just look at the first parameter of the original size and compare it. The following are the parameters of imagecopyresampled. Compare them one by one as follows: $newim: imagecreate($new_img_width, $new_img_height); Blank layer created $im: imagecreatefromjpeg($filename); Read in the original image 0: The x point from which the output image should start (the point of the image output can be specified, and the unspecified position will be the layer color or image you create) 0: The y point from which side the output graph should start (same as above) 7: From which side of the original picture should…
PHP uses header() to output image cache examples, _PHP tutorial
PHP uses header() to output image cache instances, The example in this article describes how PHP uses header() to output image cache. Share it with everyone for your reference. The specific analysis is as follows: When we generate the verification code, we need to directly enter the image. Usually we use header(“Content-type: image/jpeg”); to achieve this. Here is a brief introduction. In many developments, we try to use header(“Content-type: image/jpeg”); to output pictures, and try to use some PHP image processing technology to make the output pictures more intelligent and dynamic. But we often encounter new problems. Unless you specify different URL structures and use server technology to cache the images, it is very likely that these output images will consume a lot of traffic. How to cache them and call the cache the next time the user visits? (provided you want this image to remain unchanged) The code is as follows: // put this above any php image generation code: session_start(); header(“Cache-Control: private, max-age=10800, pre-check=10800”); header(“Pragma: private”); header(“Expires: ” . date(DATE_RFC822,strtotime(” 2 day”))); Add the above code above header(“Content-type: image/jpeg”);, which will specify the cache time of the current page (two days) and use this cache time node on…
PHP implements using regular expressions to convert URLs in text into link tags, _PHP tutorial
php implements using regular expressions to convert URLs in text into link tags, The code is as follows: function text2links($str=”) { if($str==” or !preg_match(‘/(http|www\.|@)/i’, $str)) { return $str; } $lines = explode(“\n”, $str); $new_text = ”; while (list($k,$l) = each($lines)) { // replace links: $l = preg_replace(“/([ \t]|^)www\./i”, “\\1http://www.”, $l); $l = preg_replace(“/([ \t]|^)ftp\./i”, “\\1ftp://ftp.”, $l); $l = preg_replace(“/(http:\/\/[^ )\r\n!]+)/i”, “\\1”, $l); $l = preg_replace(“/(https:\/\/[^ )\r\n!]+)/i”, “\\1”, $l); $l = preg_replace(“/(ftp:\/\/[^ )\r\n!]+)/i”, “\\1”, $l); $l = preg_replace( “/([-a-z0-9_]+(\.[_a-z0-9-]+)*@([a-z0-9-]+(\.[a-z0-9-]+) +))/i”, “\\1”, $l); $new_text .= $l.”\n”; } return $new_text; } http://www.bkjia.com/PHPjc/920971.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/920971.htmlTechArticlephp uses regular expressions to convert URLs in text into link tags. The code is as follows: function text2links($str=”) { if($str==” or !preg_match(‘/(http|www\ .|@)/i’, $str))…
PHP method to implement HTML to generate PDF files, _PHP tutorial
PHP implements HTML to generate PDF files, The example in this article describes the method of using HTML2FPDF and wkhtmltoimage to directly generate a file in pdf format from web page html in Linux. It is shared with everyone for your reference. The specific implementation method is as follows: I found an open source program developed based on the FPDF and HTML2FPDF source codes. The author is very awesome. It basically solves the problem of garbled characters in Chinese (as well as Japanese, Korean, Southeast Asian and global languages). It can be tested in Windows/Linux development environment and does not require the installation of other component support. It is good news for website developers who do not have VPS and independent servers. Not much to say, the source code name is MPDF, the official address is: http://www.mpdf1.com/ and it has been updated to version 5.6. Download it from the official website, unzip it to the website directory, and use it. The code is as follows: <? php include(‘mpdf.php’); $mpdf=new mPDF(‘UTF-8′,’A4’,”,”,15,15,44,15); $mpdf->useAdobeCJK = true; $mpdf->SetAutoFont(AUTOFONT_ALL); $mpdf->SetDisplayMode(‘fullpage’); //$mpdf->watermark_fOnt= ‘GB’; //$mpdf->SetWatermarkText(‘China Watermark’,0.1); $url = ‘http://www.yourdomain.com/’; $strCOntent= file_get_contents($url); //print_r($strContent);die; $mpdf->showWatermarkText = true; $mpdf->SetAutoFont(); //$mpdf->SetHTMLHeader( ‘head’ ); //$mpdf->SetHTMLFooter( ‘Bottom’ ); $mpdf->WriteHTML($strContent); $mpdf->Output(‘ss.pdf’); //$mpdf->Output(‘tmp.pdf’,true); //$mpdf->Output(‘tmp.pdf’,’d’); //$mpdf->Output();…
ThinkPHP file upload example tutorial, _PHP tutorial
ThinkPHP file upload tutorial, File uploading is a common function in many PHP program projects. Today, this article will share a complete example to implement the ThinkPHP file uploading function. The specific methods are as follows: 1. Action part: FileAction.class.php page code is as follows: select(); $this->assign(‘filelist’,$list); $this->display(); } function upload(){ //Submit the file upload address to him, and return a message after the upload is completed to write it to the database if(empty($_FILES)){ $this->error(‘Must choose to upload file’); }else{ $a=$this->up(); if(isset($a)){ //Custom c method to write to the database if($this->c($a)){ $this->success(‘Upload successful’); } else{ $this->error(‘Failed to write to database’); } }else{ $this-error(‘Unexpected file upload, please contact the system administrator’); } } } private function c($data){ $file=M(‘file’); $num = ‘0’; for($i = 0; $i data($data)->add()) { $num++; } } if($num==count($data)-1) { return true; }else { return false; } } private function up(){ //Complete the call to the file upload class related to thinkphp import(‘@.Org.UploadFile’);//Copy the upload class UploadFile.class.php to the Lib/Org folder $upload=new UploadFile(); $upload->maxSize=’1000000′;//The default is -1, no limit on upload size $upload->savePath=’./Public/Upload/’;//It is recommended to save the path in the same directory as the main file or in a subdirectory of the same directory. $upload->saveRule=uniqid;//File name saving rules…
PHP image upload uses microseconds as file name, _PHP tutorial
php uses microseconds for image upload as file name, $m = microtime ();$mtime = explode(‘ ‘,$m);$mtime1 = $mtime[1];$mtime2 = substr($mtime[0], 2, 6);$pic_time = “{$mtime1}{$mtime2}”; http://www.bkjia.com/PHPjc/867002.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/867002.htmlTechArticlephp uses microseconds for image upload as file name, $m = microtime (); $mtime = explode(‘ ‘ ,$m); $mtime1 = $mtime[1]; $mtime2 = substr($mtime[ 0], 2, 6); $pic_time = “{$mtime1}{$mtime2}”;…
A simple way to determine whether there are pictures in an article using PHP, _PHP tutorial
A simple way to determine whether there are pictures in an article using PHP, The PHP program in this article is used to determine whether the article contains pictures. The main implementation idea is to use preg_match to check whether there is a matching “<img" in the content. Apart from the examples described in this article, we can also use preg_match to Determine many things, such as whether there is "@" in the email address, whether there is a mobile phone number, etc. Without further ado, here is the main implementation code: $url=”http://XXXXX/article/012.html”; $cOntent=file_get_contents($url); //Read article page source code if(preg_match(“//”,$content)){ //Perform regular matching to determine whether there is a picture echo “Picture detected”; }else{ echo “No picture found”; } http://www.bkjia.com/PHPjc/851355.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/851355.htmlTechArticleA simple way to use PHP to determine whether there are pictures in the article. The PHP program in this article is used to determine whether the article contains pictures. The main implementation idea is to use preg_match to check whether the content contains…