// ReformatImages converts images in one dir to another using default
// formats for Kindle and PDF.
166090
func ReformatImages(baseSrcDir, baseOutDir string, copyType CopyType) error {
	var err error
	baseSrcDir, err = filepath.Abs(strings.TrimSpace(baseSrcDir))
	if err != nil {
		return err
	}
	baseOutDir, err = filepath.Abs(strings.TrimSpace(baseOutDir))
	if err != nil {
		return err
	}
	return reformatImagesSubdir(baseSrcDir, baseOutDir, "", copyType)
}
574930
func replaceAllInChunks(chunks []formatChunk, re *regexp.Regexp, repl func(string) template.HTML) []formatChunk {
	var ret []formatChunk
	for _, chunk := range chunks {
		if len(chunk.html) != 0 {
			ret = append(ret, chunk)
			continue
		}
		s := chunk.str
		for len(s) != 0 {
			loc := re.FindStringIndex(s)
			if loc == nil {
				ret = append(ret, formatChunk{str: s})
				break
			}
			if loc[0] > 0 {
				ret = append(ret, formatChunk{str: s[:loc[0]]})
			}
			html := repl(s[loc[0]:loc[1]])
			ret = append(ret, formatChunk{html: html})
			s = s[loc[1]:]
		}
	}
	return ret
}
218317
func ReorderPhotos(client *flickr.FlickrClient, photosetId, primaryId string, photoIds []string) (*flickr.BasicResponse, error) {
	return EditPhotos(client, photosetId, primaryId, photoIds)
}
220322
func (f *Fetcher) FetchImages(al *apps.Apps) error {
	return al.Walk(func(app *apps.App) error {
		d, err := DistFromImageString(app.Image)
		if err != nil {
			return err
		}
		h, err := f.FetchImage(d, app.Image, app.Asc)
		if err != nil {
			return err
		}
		app.ImageID = *h
		return nil
	})
}
986578
func (image *Image) Flatten() error {
	if image.image == nil {
		return errors.New(fmt.Sprintf("RBD image %s is not open", image.name))
	}

	return GetError(C.rbd_flatten(image.image))
}
1350398
func ReorderImageLayers(image *imageapi.Image) {
	if len(image.DockerImageLayers) == 0 {
		return
	}

	layersOrder, ok := image.Annotations[imageapi.DockerImageLayersOrderAnnotation]
	if !ok {
		switch image.DockerImageManifestMediaType {
		case schema1.MediaTypeManifest, schema1.MediaTypeSignedManifest:
			layersOrder = imageapi.DockerImageLayersOrderAscending
		case schema2.MediaTypeManifest:
			layersOrder = imageapi.DockerImageLayersOrderDescending
		default:
			return
		}
	}

	if layersOrder == imageapi.DockerImageLayersOrderDescending {
		// reverse order of the layers (lowest = 0, highest = i)
		for i, j := 0, len(image.DockerImageLayers)-1; i < j; i, j = i+1, j-1 {
			image.DockerImageLayers[i], image.DockerImageLayers[j] = image.DockerImageLayers[j], image.DockerImageLayers[i]
		}
	}

	if image.Annotations == nil {
		image.Annotations = map[string]string{}
	}

	image.Annotations[imageapi.DockerImageLayersOrderAnnotation] = imageapi.DockerImageLayersOrderAscending
}
823775
func (daemon *Daemon) refreshImage(s *container.Snapshot, ctx *listContext) (*types.Container, error) {
	c := s.Container
	image := s.Image // keep the original ref if still valid (hasn't changed)
	if image != s.ImageID {
		img, err := daemon.imageService.GetImage(image)
		if _, isDNE := err.(images.ErrImageDoesNotExist); err != nil && !isDNE {
			return nil, err
		}
		if err != nil || img.ImageID() != s.ImageID {
			// ref changed, we need to use original ID
			image = s.ImageID
		}
	}
	c.Image = image
	return &c, nil
}
1002968
func renameDuplicates(bf []*blobFile) sortedFiles {
	noDup := make(map[string]blob.Ref)
	// use a map to detect duplicates and rename them
	for _, file := range bf {
		if _, ok := noDup[file.path]; ok {
			// path already exists, so rename
			suffix := 0
			var newname string
			for {
				suffix++
				ext := path.Ext(file.path)
				newname = fmt.Sprintf("%s(%d)%s",
					file.path[:len(file.path)-len(ext)], suffix, ext)
				if _, ok := noDup[newname]; !ok {
					break
				}
			}
			noDup[newname] = file.blobRef
		} else {
			noDup[file.path] = file.blobRef
		}
	}

	// reinsert in a slice and sort it
	var sorted sortedFiles
	for p, b := range noDup {
		sorted = append(sorted, &blobFile{path: p, blobRef: b})
	}
	sort.Sort(sorted)
	return sorted
}
720925
func LoadImages(cmd bootstrapper.CommandRunner, images []string, cacheDir string) error {
	var g errgroup.Group
	// Load profile cluster config from file
	cc, err := config.Load()
	if err != nil && !os.IsNotExist(err) {
		glog.Errorln("Error loading profile config: ", err)
	}
	for _, image := range images {
		image := image
		g.Go(func() error {
			src := filepath.Join(cacheDir, image)
			src = sanitizeCacheDir(src)
			if err := loadImageFromCache(cmd, cc.KubernetesConfig, src); err != nil {
				glog.Warningf("Failed to load %s: %v", src, err)
				return errors.Wrapf(err, "loading image %s", src)
			}
			return nil
		})
	}
	if err := g.Wait(); err != nil {
		return errors.Wrap(err, "loading cached images")
	}
	glog.Infoln("Successfully loaded all cached images.")
	return nil
}
901824
func (bow *Browser) Images() []*Image {
	images := make([]*Image, 0, InitialAssetsSliceSize)
	bow.Find("img").Each(func(_ int, s *goquery.Selection) {
		src, err := bow.attrToResolvedUrl("src", s)
		if err == nil {
			images = append(images, NewImageAsset(
				src,
				bow.attrOrDefault("id", "", s),
				bow.attrOrDefault("alt", "", s),
				bow.attrOrDefault("title", "", s),
			))
		}
	})

	return images
}
1290739
func formatMap(m map[string]string) string {
	var l string
	for key, value := range m {
		l += key + "=" + fmt.Sprintf("%q", value) + "\n"
	}
	return l
}
898888
func (i ImageManifest) Blobs() []digest.Digest {
	digests := []digest.Digest{}
	for _, descriptor := range i.SchemaV2Manifest.References() {
		digests = append(digests, descriptor.Digest)
	}
	return digests
}
764750
func templateCleanImageName(s string) string {
	if reImageFamily.MatchString(s) {
		return s
	}
	b := []byte(strings.ToLower(s))
	newb := make([]byte, len(b))
	for i := range newb {
		if isalphanumeric(b[i]) {
			newb[i] = b[i]
		} else {
			newb[i] = '-'
		}
	}
	return string(newb)
}
1258298
func (s *EnvironmentLanguage) SetImages(v []*EnvironmentImage) *EnvironmentLanguage {
	s.Images = v
	return s
}
594563
func (c *Client) PruneImages(opts PruneImagesOptions) (*PruneImagesResults, error) {
	path := "/images/prune?" + queryString(opts)
	resp, err := c.do("POST", path, doOptions{context: opts.Context})
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()
	var results PruneImagesResults
	if err := json.NewDecoder(resp.Body).Decode(&results); err != nil {
		return nil, err
	}
	return &results, nil
}
1139006
func (g *Generator) SetVMImageFormat(format string) error {
	switch format {
	case "raw":
	case "qcow2":
	case "vdi":
	case "vmdk":
	case "vhd":
	default:
		return fmt.Errorf("Commonly supported formats are: raw, qcow2, vdi, vmdk, vhd")
	}
	g.initConfigVMImage()
	g.Config.VM.Image.Format = format
	return nil
}
1036057
func (d *Daemon) ListImages(ctx context.Context, spec update.ResourceSpec) ([]v6.ImageStatus, error) {
	return d.ListImagesWithOptions(ctx, v10.ListImagesOptions{Spec: spec})
}