當前位置: 首頁>>代碼示例>>Python>>正文


Python images.ImageFile方法代碼示例

本文整理匯總了Python中django.core.files.images.ImageFile方法的典型用法代碼示例。如果您正苦於以下問題:Python images.ImageFile方法的具體用法?Python images.ImageFile怎麽用?Python images.ImageFile使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在django.core.files.images的用法示例。


在下文中一共展示了images.ImageFile方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_logo_image

# 需要導入模塊: from django.core.files import images [as 別名]
# 或者: from django.core.files.images import ImageFile [as 別名]
def test_logo_image(self):
        homepage = HomePage.objects.get()
        self.assertIsNone(homepage.logo_image)
        with self.settings(CONFERENCE_ID=self.conference.id):
            # Test that default logo image appears.
            response = self.client.get(homepage.url)
            self.assertContains(response, "/logo.png")
            # Replace default logo with a new image.
            test_logo_name = Faker().uuid4()
            image_file = ImageFile(
                open("conf_site/cms/tests/test-logo.png", "rb"), test_logo_name
            )
            ImageModel = get_image_model()
            image = ImageModel(file=image_file)
            # The image must be saved before it is attached
            # to the homepage.
            image.save()
            homepage.logo_image = image
            homepage.save()
            response = self.client.get(homepage.url)
            self.assertNotContains(response, "/logo.288981a8dfa8.png")
            self.assertContains(response, test_logo_name) 
開發者ID:pydata,項目名稱:conf_site,代碼行數:24,代碼來源:test_homepage_context.py

示例2: test_get

# 需要導入模塊: from django.core.files import images [as 別名]
# 或者: from django.core.files.images import ImageFile [as 別名]
def test_get(self):
        """Test GET when there are odlcs."""
        odlc = Odlc(mission=self.mission,
                    user=self.team,
                    odlc_type=interop_api_pb2.Odlc.STANDARD)
        odlc.save()

        with open(test_image('A.jpg'), 'rb') as f:
            odlc.thumbnail.save('%d.%s' % (odlc.pk, 'jpg'), ImageFile(f))
        odlc.save()

        response = self.client.get(odlcs_review_url)
        self.assertEqual(200, response.status_code)
        data = json.loads(response.content)
        self.assertEqual(1, len(data))
        self.assertIn('odlc', data[0])
        self.assertIn('type', data[0]['odlc'])
        self.assertEqual('STANDARD', data[0]['odlc']['type']) 
開發者ID:auvsi-suas,項目名稱:interop,代碼行數:20,代碼來源:odlcs_test.py

示例3: setUpClass

# 需要導入模塊: from django.core.files import images [as 別名]
# 或者: from django.core.files.images import ImageFile [as 別名]
def setUpClass(cls):
        super(BaseOrphanedMediaCommandTestsMixin, cls).setUpClass()
        set_media_tag(get_random_name())
        TestModelWithoutFile.objects.create(name='without file')
        TestModel.objects.create(name='without file')
        TestImageModel.objects.create(name='without image')
        cls.file = cls.add_file_to_model(TestModel(name='with file')).file.name
        cls.file_2 = cls.add_file_to_model(TestModel(name='with file')).file.name
        image_model_instance = cls.add_file_to_model(TestImageModel(name='with file and image'))
        cls.file_removed = image_model_instance.file.name
        cls.add_file_to_model(image_model_instance)
        cls.file_removed_2 = image_model_instance.file.name
        cls.add_file_to_model(image_model_instance)
        cls.file_3 = image_model_instance.file.name
        image = ImageFile(open(os.path.join('tests', 'dummy-files', 'dummy-image.jpg'), 'rb'))
        image_model_instance.image.save(get_random_name(), image)
        cls.file_4 = image_model_instance.image.name 
開發者ID:klis87,項目名稱:django-cloudinary-storage,代碼行數:19,代碼來源:test_commands.py

示例4: setUp

# 需要導入模塊: from django.core.files import images [as 別名]
# 或者: from django.core.files.images import ImageFile [as 別名]
def setUp(self):
        """
        Creates a pristine temp directory (or deletes and recreates if it
        already exists) that the model uses as its storage directory.

        Sets up two ImageFile instances for use in tests.
        """
        if os.path.exists(temp_storage_dir):
            shutil.rmtree(temp_storage_dir)
        os.mkdir(temp_storage_dir)

        file_path1 = os.path.join(os.path.dirname(__file__), '4x8.png')
        self.file1 = self.File(open(file_path1, 'rb'), name='4x8.png')

        file_path2 = os.path.join(os.path.dirname(__file__), '8x4.png')
        self.file2 = self.File(open(file_path2, 'rb'), name='8x4.png') 
開發者ID:nesdis,項目名稱:djongo,代碼行數:18,代碼來源:test_imagefield.py

示例5: handle

# 需要導入模塊: from django.core.files import images [as 別名]
# 或者: from django.core.files.images import ImageFile [as 別名]
def handle(self, *args, **options):
        # Get the only instance of Magazine Index Page
        magazine_index_page = MagazineIndexPage.objects.get()

        with open(options["file"]) as import_file:
            issues = csv.DictReader(import_file)

            for issue in issues:
                response = requests.get(issue["cover_image_url"])
                image_file = BytesIO(response.content)

                image = Image(
                    title=issue["title"] + " cover image",
                    file=ImageFile(image_file, name=issue["cover_image_file_name"]),
                )

                image.save()

                import_issue = MagazineIssue(
                    title=issue["title"],
                    publication_date=issue["publication_date"],
                    first_published_at=issue["publication_date"],
                    issue_number=issue["issue_number"],
                    cover_image=image,
                )

                # Add issue to site page hiererchy
                magazine_index_page.add_child(instance=import_issue)
                magazine_index_page.save()

        self.stdout.write("All done!") 
開發者ID:WesternFriend,項目名稱:WF-website,代碼行數:33,代碼來源:import_issues.py

示例6: upload_img

# 需要導入模塊: from django.core.files import images [as 別名]
# 或者: from django.core.files.images import ImageFile [as 別名]
def upload_img(model, name, path):
    with open(path, 'rb')as f:
        img = ImageFile(f)
        a = model(name=name)
        a.img.save(name, img) 
開發者ID:gojuukaze,項目名稱:DeerU,代碼行數:7,代碼來源:0002_auto_20180716_1327.py

示例7: get_test_image_file

# 需要導入模塊: from django.core.files import images [as 別名]
# 或者: from django.core.files.images import ImageFile [as 別名]
def get_test_image_file(filename='test.png', colour='white', size=(640, 480)):
    f = BytesIO()
    image = PIL.Image.new('RGBA', size, colour)
    image.save(f, 'PNG')
    return ImageFile(f, name=filename) 
開發者ID:wagtail,項目名稱:wagtail,代碼行數:7,代碼來源:utils.py

示例8: get_test_image_file_jpeg

# 需要導入模塊: from django.core.files import images [as 別名]
# 或者: from django.core.files.images import ImageFile [as 別名]
def get_test_image_file_jpeg(filename='test.jpg', colour='white', size=(640, 480)):
    f = BytesIO()
    image = PIL.Image.new('RGB', size, colour)
    image.save(f, 'JPEG')
    return ImageFile(f, name=filename) 
開發者ID:wagtail,項目名稱:wagtail,代碼行數:7,代碼來源:utils.py

示例9: get_test_image_file_webp

# 需要導入模塊: from django.core.files import images [as 別名]
# 或者: from django.core.files.images import ImageFile [as 別名]
def get_test_image_file_webp(filename='test.webp', colour='white', size=(640, 480)):
    f = BytesIO()
    image = PIL.Image.new('RGB', size, colour)
    image.save(f, 'WEBP')
    return ImageFile(f, name=filename) 
開發者ID:wagtail,項目名稱:wagtail,代碼行數:7,代碼來源:utils.py

示例10: dataToImageFile

# 需要導入模塊: from django.core.files import images [as 別名]
# 或者: from django.core.files.images import ImageFile [as 別名]
def dataToImageFile(data):
    image = NamedTemporaryFile(delete=False)
    image.write(data)
    image.flush()
    return ImageFile(image) 
開發者ID:MagiCircles,項目名稱:SchoolIdolAPI,代碼行數:7,代碼來源:utils.py

示例11: shrunkImage

# 需要導入模塊: from django.core.files import images [as 別名]
# 或者: from django.core.files.images import ImageFile [as 別名]
def shrunkImage(picture, filename):
    api_key = settings.TINYPNG_API_KEY
    if not api_key or not filename.endswith('.png'):
        return picture
    img_shrunked = NamedTemporaryFile(delete=False)
    shrink_info = shrink_file(
            picture.name,
            api_key=api_key,
            out_filepath=img_shrunked.name
    )
    img_shrunked.flush()
    return ImageFile(img_shrunked) 
開發者ID:MagiCircles,項目名稱:SchoolIdolAPI,代碼行數:14,代碼來源:utils.py

示例12: downloadFile

# 需要導入模塊: from django.core.files import images [as 別名]
# 或者: from django.core.files.images import ImageFile [as 別名]
def downloadFile(url):
    img_temp = NamedTemporaryFile(delete=True)
    req = urllib2.Request(url, headers={ 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.94 Safari/537.36' })
    img_temp.write(urllib2.urlopen(req).read())
    img_temp.flush()
    return ImageFile(img_temp) 
開發者ID:MagiCircles,項目名稱:SchoolIdolAPI,代碼行數:8,代碼來源:importbasics.py

示例13: _store_external_image

# 需要導入模塊: from django.core.files import images [as 別名]
# 或者: from django.core.files.images import ImageFile [as 別名]
def _store_external_image(image_url: str) -> MozImage:
    """Download an image from the given URL and store it as a Wagtail image"""
    response = requests.get(image_url)
    filename = image_url.split("/")[-1]
    image = MozImage(
        title=filename, file=ImageFile(BytesIO(response.content), name=filename)
    )
    image.save()
    return image 
開發者ID:mdn,項目名稱:developer-portal,代碼行數:11,代碼來源:utils.py

示例14: __call__

# 需要導入模塊: from django.core.files import images [as 別名]
# 或者: from django.core.files.images import ImageFile [as 別名]
def __call__(self, resolution, image_format='JPEG', name=None):

        filename = name or 'default.{}'.format(image_format.lower())
        color = 'blue'
        image = Image.new('RGB', resolution, color)
        image_data = BytesIO()
        image.save(image_data, image_format)
        image_content = base.ContentFile(image_data.getvalue())
        return images.ImageFile(image_content.file, filename) 
開發者ID:liqd,項目名稱:adhocracy4,代碼行數:11,代碼來源:factories.py

示例15: get_image

# 需要導入模塊: from django.core.files import images [as 別名]
# 或者: from django.core.files.images import ImageFile [as 別名]
def get_image(self, name):
        """Get one of the test images from the test data directory."""
        return ImageFile(open(TEST_DATA_ROOT + name + '.png')) 
開發者ID:edx,項目名稱:credentials,代碼行數:5,代碼來源:test_models.py


注:本文中的django.core.files.images.ImageFile方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。