pip install Wand
from wand.image import Image
with Image(filename='pikachu.png') as original:
with original.convert('jpeg') as converted:
# operations to a jpeg image...
pass
import magic
, а дальше уже делать то вы планируете делать... это надо ввести в python или в командную строку
# Импорт библиотеки python-magic
import magic
# Открытия файла test.pdf который лежит в папке testdata
magic.from_file("testdata/test.pdf")
# Вывод верхней команды
# --- 'PDF document, version 1.2'
# Открытия файла test.pdf который лежит в папке testdata НО из буфера.
magic.from_buffer(open("testdata/test.pdf", "rb").read(2048))
# Вывод верхней команды
# --- 'PDF document, version 1.2'
# Открытия файла test.pdf который лежит в папке testdata
# с ключевым аргументом <b>mime</b>
magic.from_file("testdata/test.pdf", mime=True)
# Вывод верхней команды, который показывает MIME
# --- 'application/pdf'
def create(self, validated_data):
obtainitem_data = validated_data.pop('nomenclatures')
obtain = ObtainingDocument.objects.create(**validated_data)
item_list = [
ObtainingDocumentItem(
amount=item['amount'],
nomenclature=item['nomenclature'],
obtaining_doc=obtain,
) for item in obtainitem_data
]
for item in item_list:
ObtainingDocumentItem.objects.get_or_create(item)
return obtain
class CreateUserSerializer(serializers.ModelSerializer):
class Meta:
model = User
fields = ['email', 'username', 'password']
extra_kwargs = {'password': {'write_only': True}}
def create(self, validated_data):
user = User(
email=validated_data['email'],
username=validated_data['username']
)
user.set_password(validated_data['password'])
user.save()
return use
def create(self, validated_data):
item_list = validated_data.pop('item_list')
for item in item_list:
item.save()
return None
def perform_create(self, serializer):
serializer.save(user=self.request.user)
$1 = 'file1.php';
$2 = 'file2.php';
$3 = 'file3.php';
$4 = 'file4.php';
$5 = 'file.php';
$file = rand($1, $5) // Если так в php не работает извиняюсь
<body>
<?php include ($file);?>
</body>
<?php
// Создаем массив с названиями файлов
$files = array('file1.php', 'file2.php', 'file3.php', 'file4.php', 'file5.php');
// Перемешиваем массив
shuffle($files);
// Задаем количество файлов, которые вы хотите вывести
$files_to_include = 3;
// Выводим указанное количество случайно выбранных файлов
for ($i = 0; $i < $files_to_include; $i++) {
include $files[$i];
}
?>