Last active
January 31, 2017 11:39
-
-
Save vasilukwolf/63380f313a0f3818c91bc3a52878720b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
$dir ="/home/bitrix/ext_www/host.svarbi.ru/upload/iblock/"; | |
function optimizeimage($input,$output) | |
{ | |
$images = new Imagick(glob($input)); | |
foreach($images as $image) { | |
$image->stripimage(); | |
$image->setImageCompression(Imagick::COMPRESSION_JPEG); | |
$image->setImageCompressionQuality(78); | |
} | |
$images->writeimages($output,true); | |
} | |
foreach (scandir($dir) as $key) { | |
if('.'!=$key && '..'!=$key){ | |
$input ="/home/bitrix/ext_www/host.svarbi.ru/upload/iblock/".$key."/*.jp*g"; | |
foreach (glob($input) as $filename) { | |
$output = "/home/bitrix/ext_www/host.svarbi.ru/ttt/aaa/".$key."/".basename($filename); | |
} | |
echo $key."\n"; | |
optimizeimage($input,$output); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
$dir ="/home/bitrix/ext_www/host.svarbi.ru/upload/iblock/"; | |
$dir2="/home/bitrix/ext_www/host.svarbi.ru/imgbackup/"; | |
function createdir($dir,$dir2){ | |
foreach (scandir($dir) as $key) { | |
$structure = $dir2.$key."/"; | |
if('.'!=$key && '..'!=$key){ | |
if (!mkdir($structure, 0755, true)) { | |
die('Не удалось создать директории...'); | |
} | |
} | |
} | |
} | |
createdir($dir,$dir2); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
$dir ="/home/bitrix/ext_www/host.svarbi.ru/upload/iblock/"; | |
function optimizeimage($input,$output) | |
{ | |
$images = new Imagick(glob($input)); | |
foreach($images as $image) { | |
$image->stripimage(); | |
$image->setImageCompression(Imagick::COMPRESSION_JPEG); | |
$image->setImageCompressionQuality(78); | |
} | |
$images->writeimages($output,true); | |
} | |
$path = '/home/bitrix/ext_www/host.svarbi.ru/'; | |
$input =$path."/upload/iblock/*/*.jp*g"; | |
foreach (glob($input) as $filename) { | |
preg_match("/([\w\s]+)\/?$/", dirname($filename), $matches); | |
$backup = $path."/imgbackup".$matches[1]."/".basename($filename); | |
if(!copy($input,$backup)){ | |
echo "Ошибка копирования"; | |
} | |
// $output = dirname($filename)."/".basename($filename); | |
// unlink($input); | |
// optimizeimage($input,$output); | |
echo $backup."\n"; | |
} | |
?> | |
xorcare
commented
Jan 30, 2017
<?php
foreach (scandir($dir) as $key) {
if('.'!=$key && '..'!=$key){
$input ="/home/bitrix/ext_www/host.svarbi.ru/upload/iblock/".$key."/*.jp*g";
foreach (glob($input) as $filename) {
$backup = "/home/bitrix/ext_www/host.svarbi.ru/imgbackup";
copy($input,$backup);
$output = "/home/bitrix/ext_www/host.svarbi.ru/ttt/aaa/".$key."/".basename($filename);
echo $key."\n";
unlink($input);
optimizeimage($backup,$output);
}
}
}
<?
$dir ="/home/bitrix/ext_www/host.svarbi.ru/upload/iblock/";
function optimizeimage($input,$output)
{
$images = new Imagick(glob($input));
foreach($images as $image) {
$image->stripimage();
$image->setImageCompression(Imagick::COMPRESSION_JPEG);
$image->setImageCompressionQuality(78);
}
$images->writeimages($output,true);
}
foreach (scandir($dir) as $key) {
if('.'!=$key && '..'!=$key){
$input ="/home/bitrix/ext_www/host.svarbi.ru/upload/iblock/".$key."/*.jp*g";
foreach (glob($input) as $filename) {
$backup = "/home/bitrix/ext_www/host.svarbi.ru/imgbackup";
copy($input,$backup);
$output = "/home/bitrix/ext_www/host.svarbi.ru/ttt/aaa/".$key."/".basename($filename);
echo $key."\n";
unlink($input);
optimizeimage($backup,$output);
}
}
}
Fatal error: Uncaught exception 'ImagickException' with message 'Can not process empty Imagick object' in /home/bitrix/ext_www/host.svarbi.ru/ttt/imagemagick.php:7
Stack trace:
#0 /home/bitrix/ext_www/host.svarbi.ru/ttt/imagemagick.php(7): Imagick->valid()
#1 /home/bitrix/ext_www/host.svarbi.ru/ttt/imagemagick.php(25): optimizeimage('/home/bitrix/ex...', '/home/bitrix/ex...')
#2 {main}
thrown in /home/bitrix/ext_www/host.svarbi.ru/ttt/imagemagick.php on line 7
$input ="/home/bitrix/ext_www/host.svarbi.ru/upload/iblock/*/*.jp*g";
foreach (glob($input) as $filename) {
$backup = "/home/bitrix/ext_www/host.svarbi.ru/imgbackup";
copy($input,$backup);
$output = "/home/bitrix/ext_www/host.svarbi.ru/ttt/aaa/".$key."/".basename($filename);
echo $key."\n";
//unlink($input);
optimizeimage($input,$output);
}
$input =$_SERVER['DOCUMENT_ROOT']."/upload/iblock/*/*.jp*g";
foreach (glob($input) as $filename) {
$backup = $_SERVER['DOCUMENT_ROOT']."/imgbackup";
copy($input,$backup);
$output = $_SERVER['DOCUMENT_ROOT']."/ttt/aaa/".dirname($filename)."/".basename($filename);
// echo $key."\n";
//unlink($input);
//optimizeimage($input,$output);
echo $output."\n";
}
//print_r(glob($input));
<?
$dir ="/home/bitrix/ext_www/host.svarbi.ru/upload/iblock/";
function optimizeimage($input,$output)
{
$images = new Imagick(glob($input));
foreach($images as $image) {
$image->stripimage();
$image->setImageCompression(Imagick::COMPRESSION_JPEG);
$image->setImageCompressionQuality(78);
}
$images->writeimages($output,true);
}
$input =$_SERVER['DOCUMENT_ROOT']."/upload/iblock/*/*.jp*g";
foreach (glob($input) as $filename) {
preg_match("/([\w\s]+)\/?$/", dirname($filename), $matches);
$backup = $_SERVER['DOCUMENT_ROOT']."/imgbackup/".$matches[1]."/".basename($filename);
copy($input,$backup);
$output = dirname($filename)."/".basename($filename);
unlink($input);
optimizeimage($input,$output);
echo $backup."<br/>\n";
}
?>
<?
$dir ="/home/bitrix/ext_www/host.svarbi.ru/upload/iblock/";
function optimizeimage($input,$output)
{
$images = new Imagick(glob($input));
foreach($images as $image) {
$image->stripimage();
$image->setImageCompression(Imagick::COMPRESSION_JPEG);
$image->setImageCompressionQuality(78);
}
$images->writeimages($output,true);
}
$path = '/home/bitrix/ext_www/host.svarbi.ru/';
$input =$path."/upload/iblock/*/*.jp*g";
foreach (glob($input) as $filename) {
preg_match("/([\w\s]+)\/?$/", dirname($filename), $matches);
$backup = $path."/imgbackup".$matches[1]."/".basename($filename);
if(!copy($input,$backup)){
echo "Ошибка копирования";
}
// $output = dirname($filename)."/".basename($filename);
// unlink($input);
// optimizeimage($input,$output);
echo $backup."\n";
}
?>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment