Jump to content
  • разработка интернет магазинов на opencart
  • доработка интернет магазинов на opencart

Модуль для массового сжатия фото в формате jpg


 Share

Recommended Posts

Добрый гдень. Ищу модуль для уменьшения размера фото в формате jpg. Сейчас на сайте фото с размером потому чтолее 50 КВ.Сайт подтормаживает, хочу ускорить его рилиту.

Нужно сжать порядка 30000 фото. Ручками это ооочень долго.

 

Link to comment
Share on other sites


1 час назад, Ezik сказал:

Сейчас на сайте фото с размером потому чтолее 50 КВ

Нужно посмотреть в Гугл ПейджСпид - возможно тормоза не из-за картинок. Или одновременно подгружается много фото - тогда гделать отложенную загрузку.

Link to comment
Share on other sites

<?xml version="1.0" encoding="utf-8"?>
<modification>
<name>OCMOD Quick Convert Images in WebP</name>
<code>webp-gd</code>
<version>1.0</version>
<author>no_name</author>
<link></link>
	<file path="catalog/model/tool/image.php">
		<operation>
			<search><![CDATA[$image_new = 'cache/']]></search>
			<add position="after"><![CDATA[$image_new_webp = 'cachewebp/' . utf8_substr($filename, 0, utf8_strrpos($filename, '.')) . '-' . (int)$width . 'x' . (int)$height . '.webp';]]></add>
		</operation>
		<operation>
			<search><![CDATA[$image_new = str_replace(]]></search>
			<add position="before" ><![CDATA[
			$gd = gd_info();
			if ($gd['WebP Support']) {
				if (!is_file(DIR_IMAGE . $image_new_webp) || (filectime(DIR_IMAGE . $image_new) > filectime(DIR_IMAGE . $image_new_webp))) {
										
					$path = '';

					$directories = explode('/', dirname($image_new_webp));

					foreach ($directories as $directory) {
						$path = $path . '/' . $directory;

						if (!is_dir(DIR_IMAGE . $path)) {
							@mkdir(DIR_IMAGE . $path, 0777);
						}
					}
					
					$image_webp = new Image(DIR_IMAGE . $image_old);
					$image_webp->resize($width, $height);
					$image_webp->save_webp(DIR_IMAGE . $image_new_webp);
				}
			}
			]]></add>
		</operation>
	</file>
	<file path="system/library/image.php">
		<operation>
			<search><![CDATA[public function save($file, $quality = 90) {]]></search>
			<add position="before"><![CDATA[
			public function save_webp($file, $quality = 90) {
				if (is_resource($this->image)) {
					imagewebp($this->image, $file, $quality);
					imagedestroy($this->image);
				}
			}
			]]></add>
		</operation>
	</file>
	<file path="system/library/response.php">
		<operation>
			<search><![CDATA[private function compress($data, $level = 0)]]></search>
			<add position="before" ><![CDATA[ 	
			public function webpRebuild($output) {
				$gd = gd_info();
				if ($gd['WebP Support']) {
					$uri = '';

					if (isset($_SERVER['REQUEST_URI'])) {
						$uri = $_SERVER['REQUEST_URI'];
					}
					
					if (stripos($uri, 'admin') === false) {
						if (isset($_SERVER['HTTP_ACCEPT']) && isset($_SERVER['HTTP_USER_AGENT'])) {
							if( strpos( $_SERVER['HTTP_ACCEPT'], 'image/webp' ) !== false ) {	
								$re = '/(cache)(.*)(\.jpg|\.png|.jpeg)/U';
								$subst = '$1webp$2.webp';
								$this->output = preg_replace($re, $subst, $this->output);
							}
						}
					}
				}
			}
			]]></add>
		</operation>
		<operation>
			<search><![CDATA[$output = $this]]></search>
			<add position="before" ><![CDATA[ $this->webpRebuild($this->output); ]]></add>
		</operation>
	</file>
</modification>

На 2.3 и на 3-ке рилииет...

Link to comment
Share on other sites

Quote

<author>no_name</author>

:mrgreen::mrgreen::mrgreen:

Это мой модуль и он бесплатный

https://www.opencart.com/index.php?route=marketplace/extension/info&extension_id=38025

 

@Ezik Бесплатная версия https://kraken.io/web-interface сжимает тысяли, но если картинка не потому чтольше 1МБ.
Платная версия гделает все. https://kraken.io/pricing

  • +1 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

On our site, cookies are used and personal data is processed to improve the user interface. To find out what and what personal data we are processing, please go to the link. If you click "I agree," it means that you understand and accept all the conditions specified in this Privacy Notice.