]>
git.immae.eu Git - github/wallabag/wallabag.git/blob - inc/3rdparty/libraries/send2kindle/images.php
4 * Get images from content and prepare to save in articles
9 * JPER quality for resize
11 const JPEG_QUALITY
= 80;
20 * Storage to keep images
29 private $_images_from_content = array();
33 * @param Strage $storage
34 * @param string $article_content
36 public function __construct(Storage
$storage, $article_content)
38 $this->_storage
= $storage;
39 $this->_content
= $article_content;
40 $this->_images_from_content
= $this->_get_images_from_content($article_content);
45 * @param string $content
46 * @return array images hashtable
48 private function _get_images_from_content($content)
51 preg_match_all('/src=\"([a-zA-Z0-9\.\/\-\_\?\+\%\~\&\;\=\:]+)\"/i', $content, $result);
58 * @return string converted content
60 public function convert()
62 foreach ( $this->_images_from_content
as $n => $image_url )
64 $image = $this->_get_image($image_url);
65 $this->_content
= str_replace($image_url, '" recindex="'.(int)basename($image), $this->_content
);
68 return $this->_content
;
73 * @param string $file path
74 * @param int $new_width max width
76 private function _resize($file, $new_width = 500)
78 list($width, $height) = getimagesize($file);
82 //setup the new size of the image
83 if( $width > $new_width )
85 $ratio = $height/$width;
86 $new_height = $new_width * $ratio;
91 $new_height = $height;
95 $new_image = imagecreatetruecolor($new_width, $new_height);
97 $type = exif_imagetype ( $file );
102 $old_image = imagecreatefromjpeg($file);
103 imagecopyresampled($new_image, $old_image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
104 imagejpeg($new_image, $file, self
::JPEG_QUALITY
);
107 $old_image = imagecreatefrompng($file);
108 imagecopyresampled($new_image, $old_image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
109 imagepng($new_image, $file);
112 $old_image = imagecreatefromgif($file);
113 imagecopyresampled($new_image, $old_image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
114 imagegif($new_image, $file);
121 * @return string image path
123 private function _get_image($url)
125 $image_data = @file_get_contents($url);
127 if ( $image_data !== false )
129 $image_name = $this->_storage
->save_image($image_data);
130 $this->_resize($image_name);